Skip to contentSkip to conversation

should swap-file opened with O_DIRECT?

RFC Yingchao Zhou 2 participants 2 messages Oct 10, 2005

lore
Share & tools
lore
#0 lore raw

The sys_swapon system call open the swap-file through
filp_open(..., O_RDWR|O_LARGEFILE,...).
In this way, I think that the pageout process of anonymous
pages finally will write them out through (swap-file)->f_ops->write, and it will result in caches of swapfile. However, swapping only happens when memory is tight. So why not set O_DIRECT? Is there any special reason to keep caches of swapfile?
Is the idea right ? Or something misunstood?

Yingchao Zhou [email protected]

#1 lore raw
Quoted 5 lines · Yingchao Zhou

The sys_swapon system call open the swap-file through
filp_open(..., O_RDWR|O_LARGEFILE,...).
In this way, I think that the pageout process of anonymous
pages finally will write them out through (swap-file)->f_ops->write,

No, they are written out by swap_writepage. The opening in sys_swapon
gets a handle of what is to be used for swap, but it then goes its own way.

Quoted 3 lines

and it will result in caches of swapfile. However, swapping only happens when memory is tight. So why not set O_DIRECT? Is there any special reason to keep caches of swapfile?

Caches of swapfile are useful (but yes, can be discarded when memory is tight). There's nothing indirect about them: the page that is mapped into userspace gets written to disk, the page that is read in from disk gets mapped back into userspace.

Hugh