RE: [PATCH 1/5] drm/ttm: add max_swap_mem in ttm_mem_global

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Need call si_swapinfo to fill those valules .

void si_swapinfo(struct sysinfo *val)

 

But that function is not exported as well.

 

Thanks

Roger(Hongbo.He)

From: dri-devel [mailto:dri-devel-bounces@xxxxxxxxxxxxxxxxxxxxx] On Behalf Of Chunming Zhou
Sent: Friday, February 02, 2018 3:38 PM
To: He, Roger <Hongbo.He@xxxxxxx>; dri-devel@xxxxxxxxxxxxxxxxxxxxx
Cc: Koenig, Christian <Christian.Koenig@xxxxxxx>
Subject: Re: [PATCH 1/5] drm/ttm: add max_swap_mem in ttm_mem_global

 

 

 

On 20180202 15:34, Chunming Zhou wrote:



On 20180202 15:22, Roger He wrote:

set its initial value as 1/2 * free swap cache size when module initial.
and adjust this value when allocate TTM memory

Signed-off-by: Roger He <Hongbo.He@xxxxxxx>
---
  drivers/gpu/drm/ttm/ttm_memory.c | 10 ++++++++--
  include/drm/ttm/ttm_memory.h     |  2 ++
  2 files changed, 10 insertions(+), 2 deletions(-)

diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
index aa0c381..b48931d 100644
--- a/drivers/gpu/drm/ttm/ttm_memory.c
+++ b/drivers/gpu/drm/ttm/ttm_memory.c
@@ -36,6 +36,7 @@
  #include <linux/mm.h>
  #include <linux/module.h>
  #include <linux/slab.h>
+#include <linux/swap.h>
    #define TTM_MEMORY_ALLOC_RETRIES 4
  @@ -372,9 +373,9 @@ int ttm_mem_global_init(struct ttm_mem_global *glob)
          kobject_put(&glob->kobj);
          return ret;
      }
-
+    /* set it as 1/2 * swap free space we can get at that time */
+    glob->max_swap_mem = get_nr_swap_pages() << (PAGE_SHIFT - 1);
      si_meminfo(&si);

Hi Roger,

I just find si_meminfo can get total swap size, see struct sysinfo definition:
 struct sysinfo {
        __kernel_long_t uptime;         /* Seconds since boot */
        __kernel_ulong_t loads[3];      /* 1, 5, and 15 minute load averages */
        __kernel_ulong_t totalram;      /* Total usable main memory size */
        __kernel_ulong_t freeram;       /* Available memory size */
        __kernel_ulong_t sharedram;     /* Amount of shared memory */
        __kernel_ulong_t bufferram;     /* Memory used by buffers */
        __kernel_ulong_t totalswap;     /* Total swap space size */
        __kernel_ulong_t freeswap;      /* swap space still available */

        __u16 procs;                    /* Number of current processes */
...

can sysinfo.totalswap be used for your change?

Regards,
David Zhou

-
      ret = ttm_mem_init_kernel_zone(glob, &si);
      if (unlikely(ret != 0))
          goto out_no_zone;
@@ -473,12 +474,17 @@ static int ttm_mem_global_reserve(struct ttm_mem_global *glob,
                    struct ttm_mem_zone *single_zone,
                    uint64_t amount, bool reserve)
  {
+    uint64_t free_swap_mem = get_nr_swap_pages() << (PAGE_SHIFT - 1);
      uint64_t limit;
      int ret = -ENOMEM;
      unsigned int i;
      struct ttm_mem_zone *zone;
        spin_lock(&glob->lock);
+    /* adjust the max_swap_mem to cover the new inserted swap space */
+    if (glob->max_swap_mem < free_swap_mem)
+        glob->max_swap_mem = free_swap_mem;

Seems using max() for exchange is more obvious, otherwise looks ok to me.

Regards,
David Zhou

+
      for (i = 0; i < glob->num_zones; ++i) {
          zone = glob->zones[i];
          if (single_zone && zone != single_zone)
diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
index 8936285..ad5a557 100644
--- a/include/drm/ttm/ttm_memory.h
+++ b/include/drm/ttm/ttm_memory.h
@@ -49,6 +49,7 @@
   * @work: The workqueue callback for the shrink queue.
   * @lock: Lock to protect the @shrink - and the memory accounting members,
   * that is, essentially the whole structure with some exceptions.
+ * @max_swap_mem: upper limit of swap space TTM can use
   * @zones: Array of pointers to accounting zones.
   * @num_zones: Number of populated entries in the @zones array.
   * @zone_kernel: Pointer to the kernel zone.
@@ -67,6 +68,7 @@ struct ttm_mem_global {
      struct workqueue_struct *swap_queue;
      struct work_struct work;
      spinlock_t lock;
+    uint64_t max_swap_mem;
      struct ttm_mem_zone *zones[TTM_MEM_MAX_ZONES];
      unsigned int num_zones;
      struct ttm_mem_zone *zone_kernel;

 

 

_______________________________________________
dri-devel mailing list
dri-devel@xxxxxxxxxxxxxxxxxxxxx
https://lists.freedesktop.org/mailman/listinfo/dri-devel

[Index of Archives]     [Linux DRI Users]     [Linux Intel Graphics]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux Kernel]     [Linux SCSI]     [XFree86]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Linux Kernel]     [Linux SCSI]     [XFree86]
  Powered by Linux