Skip to contentSkip to conversation

alternative swap_amount

RFC Roger Larsson 1 participant 1 message May 8, 2001 Memory management

lore
Share & tools
lore
#0 lore raw

Hi again,

Got some time to spend...

I wonder about the fairness in swap_amount (mm/vmscan.c) Suppose you have a small process with

	mm->rss <= SWAP_MIN

then swap_amount will
return SWAP_MIN

Resulting in an attempt to swap out ALL pages of that process. And if it had less pages even claim that we did not succeed...???

Shouldn't the return value at least be limited by the actual number of pages in the mm?

Rules:

	0 -> 0 (if there are no pages anyway..., must be handled)
	low -> P% of low (but require that we will finally get 0 pages left)
	high -> p% of high

One, _untested_ example, would be:

static inline int swap_amount(struct mm_struct *mm)

{
	/* begin with high, I have slightly more big than small ? */
	int nr = mm->rss >> SWAP_SHIFT;
	if (nr < SWAP_MIN) {
		nr = (mm->rss + 1) / 2; /* 0 => 0, 1 => 1, 2 => 1, 3 => 2 */
 		if (nr > SWAP_MIN)
			nr = SWAP_MIN;
	}
	return nr;
}

Compare these outputs:
rss _old _new

        0               8               0
        1               8               1
        2               8               1
        4               8               2
        8               8               4
       16               8               8
       32               8               8
       64               8               8
      128               8               8
      256               8               8
      512              16              16
     1024              32              32
     2048              64              64
     4096             128             128

/RogerL

---- original code ----
#define SWAP_SHIFT 5
#define SWAP_MIN 8

static inline int swap_amount(struct mm_struct *mm)

{
	int nr = mm->rss >> SWAP_SHIFT;
	return nr < SWAP_MIN ? SWAP_MIN : nr;
}

static int swap_out(unsigned int priority, int gfp_mask)

{
	int counter;
	int retval = 0;
	struct mm_struct *mm = current->mm;

	/* Always start by trying to penalize the process that is allocating memory*/
	if (mm)
		retval = swap_out_mm(mm, swap_amount(mm));
Signature · 7 lines
Roger Larsson
Skelleftea
Sweden
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in
the body to [email protected].  For more info on Linux MM,
see: http://www.linux.eu.org/Linux-MM/