mm: strictlimit feature -v4
Subsystems (4)
PATCH 1/1 mm: strictlimit feature -v4
The feature prevents mistrusted filesystems to grow a large number of dirty pages before throttling. For such filesystems balance_dirty_pages always check bdi counters against bdi limits. I.e. even if global "nr_dirty" is under "freerun", it's not allowed to skip bdi checks. The only use case for now is
fuse: it sets bdi max_ratio to 1% by default and system administrators are supposed to expect that this limit won't be exceeded.
The feature is on if a BDI is marked by BDI_CAP_STRICTLIMIT flag. A filesystem may set the flag when it initializes its BDI.
Changed in v2 (thanks to Andrew Morton):
- added a few explanatory comments
- cleaned up the mess in backing_dev_info foo_stamp fields: now it's clearly stated that bw_time_stamp is measured in jiffies; renamed other foo_stamp fields to reflect that they are in units of number-of-pages.
Changed in v3 (thanks to Jan Kara)
- made strictlimit a bdi flag
- introduced "bdi_dirty <= bdi_freerun" check
- removed BDI_idle and BDI_WRITTEN_BACK as redundant
- moved foo_stamp cleanup to separate patch because it's not related to strictlimit feature anymore
- corrected spelling.
Changed in v4 (thanks to Jan Kara)
- limited return value of pos_ratio_polynom() to <0,2> range
- extended a comment explaining the calculation of pos_ratio
- hid the computation of 'bdi_dirty' and friends in a helper function
- rebased to v3.11-rc6
--- fs/fuse/inode.c | 2 include/linux/backing-dev.h | 3 mm/page-writeback.c | 259 +++++++++++++++++++++++++++++++++---------- 3 files changed, 204 insertions(+), 60 deletions(-)
fs/fuse/inode.c +1 -1
@@ -929,7 +929,7 @@ static int fuse_bdi_init(struct fuse_conn *fc, struct super_block *sb) fc->bdi.name ="fuse" ; fc->bdi.ra_pages = (VM_MAX_READAHEAD *1024 ) /PAGE_CACHE_SIZE ;/* fuse does it's own writeback accounting */ - fc->bdi.capabilities =BDI_CAP_NO_ACCT_WB ; + fc->bdi.capabilities =BDI_CAP_NO_ACCT_WB |BDI_CAP_STRICTLIMIT ; err =bdi_init (&fc->bdi);if (err)
include/linux/backing-dev.h +3 -0
@@ -243,6 +243,8 @@ int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned int max_ratio);* BDI_CAP_EXEC_MAP: Can be mapped for execution * * BDI_CAP_SWAP_BACKED: Count shmem/tmpfs objects as swap-backed. +* +* BDI_CAP_STRICTLIMIT: Keep number of dirty pages below bdi threshold. */ #define BDI_CAP_NO_ACCT_DIRTY 0x00000001#define BDI_CAP_NO_WRITEBACK 0x00000002
@@ -254,6 +256,7 @@ int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned int max_ratio);#define BDI_CAP_NO_ACCT_WB 0x00000080#define BDI_CAP_SWAP_BACKED 0x00000100#define BDI_CAP_STABLE_WRITES 0x00000200 +#define BDI_CAP_STRICTLIMIT 0x00000400#define BDI_CAP_VMFLAGS \ (BDI_CAP_READ_MAP | BDI_CAP_WRITE_MAP | BDI_CAP_EXEC_MAP)
mm/page-writeback.c +200 -59
325 lines not on this page · raw message
Andrew Morton
maintainerQuoted 9 lines · On Wed, 21 Aug 2013 17:56:32 +0400 Maxim Patlasov <[email protected]>…
The feature prevents mistrusted filesystems to grow a large number of dirty pages before throttling. For such filesystems
balance_dirty_pagesalways check bdi counters against bdi limits. I.e. even if global "nr_dirty" is under "freerun", it's not allowed to skip bdi checks. The only use case for now is
fuse: it sets bdimax_ratioto 1% by default and system administrators are supposed to expect that this limit won't be exceeded.The feature is on if a BDI is marked by
BDI_CAP_STRICTLIMITflag. A filesystem may set the flag when it initializes its BDI.
Now I think about it, I don't really understand the need for this feature. Can you please go into some detail about the problematic scenarios and why they need fixing? Including an expanded descritopn of the term "mistrusted filesystem"?
Is this some theoretical happens-in-the-lab thing, or are real world users actually hurting due to the lack of this feature?
I think I'll apply it to -mm for now to get a bit of testing, but would very much like it if Fengguang could find time to review the implementation, please.
--
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-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
08/22/2013 12:38 AM, Andrew Morton D?D,N?DuN?:
Quoted 9 lines · On Wed, 21 Aug 2013 17:56:32 +0400 Maxim Patlasov<[email protected]>…
Quoted 8 lines
The feature prevents mistrusted filesystems to grow a large number of dirty pages before throttling. For such filesystems
balance_dirty_pagesalways check bdi counters against bdi limits. I.e. even if global "nr_dirty" is under "freerun", it's not allowed to skip bdi checks. The only use case for now is
fuse: it sets bdimax_ratioto 1% by default and system administrators are supposed to expect that this limit won't be exceeded.
Quoted 6 lines
Quoted 2 lines
The feature is on if a BDI is marked by
BDI_CAP_STRICTLIMITflag. A filesystem may set the flag when it initializes its BDI.Now I think about it, I don't really understand the need for this feature. Can you please go into some detail about the problematic scenarios and why they need fixing? Including an expanded descritopn of the term "mistrusted filesystem"?
Saying "mistrusted filesystem" I meant FUSE mount created by unprivileged user. Userspace fuse library provides suid binary "fusermount". Here is an excerpt from its man-page:
Quoted 6 lines
Filesystem in Userspace (FUSE) is a simple interface for userspace pro- grams to export a virtual filesystem to the Linux kernel. It also aims to provide a secure method for non privileged users to create and mount their own filesystem implementations.
fusermount is a program to mount and unmount FUSE filesystems.
I'm citing it here to emphasize the fact that running buggy or malevolent filesystem implementation is not pure theoretical. Every time you have fuse library properly installed, any user can compile and mount its own filesystem implementation.
The problematic scenario comes from the fact that nobody pays attention to the NR_WRITEBACK_TEMP counter (i.e. number of pages under fuse writeback). The implementation of fuse writeback releases original page (by calling end_page_writeback) almost immediately. A fuse request queued for real processing bears a copy of original page. Hence, if userspace fuse daemon doesn't finalize write requests in timely manner, an aggressive mmap writer can pollute virtually all memory by those temporary fuse page copies. They are carefully accounted in NR_WRITEBACK_TEMP, but nobody cares.
To make further explanations shorter, let me use "NR_WRITEBACK_TEMP problem" as a shortcut for "a possibility of uncontrolled grow of amount of RAM consumed by temporary pages allocated by kernel fuse to process writeback".
Quoted 2 lines
Is this some theoretical happens-in-the-lab thing, or are real world users actually hurting due to the lack of this feature?
The problem was very easy to reproduce. There is a trivial example filesystem implementation in fuse userspace distribution: fusexmp_fh.c. I added "sleep(1);" to the write methods, then recompiled and mounted it. Then created a huge file on the mount point and run a simple program which mmap-ed the file to a memory region, then wrote a data to the region. An hour later I observed almost all RAM consumed by fuse writeback. Since then some unrelated changes in kernel fuse made it more difficult to reproduce, but it is still possible now.
Putting this theoretical happens-in-the-lab thing aside, there is another thing that really hurts real world (FUSE) users. This is write-through page cache policy FUSE currently uses. I.e. handling write(2), kernel fuse populates page cache and flushes user data to the server synchronously. This is excessively suboptimal. Pavel Emelyanov's patches ("writeback cache policy") solve the problem, but they also make resolving NR_WRITEBACK_TEMP problem absolutely necessary. Otherwise, simply copying a huge file to a fuse mount would result in memory starvation. Miklos, the maintainer of FUSE, believes strictlimit feature the way to go.
And eventually putting FUSE topics aside, there is one more use-case for strictlimit feature. Using a slow USB stick (mass storage) in a machine with huge amount of RAM installed is a well-known pain. Let's make simple computations. Assuming 64GB of RAM installed, existing implementation of balance_dirty_pages will start throttling only after 9.6GB of RAM becomes dirty (freerun == 15% of total RAM). So, the command "cp 9GB_file /media/my-usb-storage/" may return in a few seconds, but subsequent "umount /media/my-usb-storage/" will take more than two hours if effective throughput of the storage is, to say, 1MB/sec.
After inclusion of strictlimit feature, it will be trivial to add a knob (e.g. /sys/devices/virtual/bdi/x:y/strictlimit) to enable it on demand. Manually or via udev rule. May be I'm wrong, but it seems to be quite a natural desire to limit the amount of dirty memory for some devices we are not fully trust (in the sense of sustainable throughput).
Quoted 3 lines
I think I'll apply it to -mm for now to get a bit of testing, but would very much like it if Fengguang could find time to review the implementation, please.
Great! Fengguang, please...
Thanks,
Maxim
--
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-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi Maxim,
Quoted 4 lines
Quoted 3 lines
I think I'll apply it to -mm for now to get a bit of testing, but would very much like it if Fengguang could find time to review the implementation, please.
Great! Fengguang, please...
I'm so sorry for the delays!
I'd like to test the patches out and take a look at its runtime behaviors. I've managed to setup general dd writeback tests. Do you happen to have some scripts that can specifically test out the fuse cases?
Thanks,
Fengguang
--
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-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>
Hi,
08/22/2013 06:41 PM, Fengguang Wu D?D,N?DuN?:
Quoted 5 lines
Hi Maxim,
Quoted 3 lines
Quoted 3 lines
I think I'll apply it to -mm for now to get a bit of testing, but would very much like it if Fengguang could find time to review the implementation, please.
Quoted 7 lines
Quoted 1 line
Great! Fengguang, please...
I'm so sorry for the delays!
I'd like to test the patches out and take a look at its runtime behaviors. I've managed to setup general dd writeback tests. Do you happen to have some scripts that can specifically test out the fuse cases?
I used ordinary dd over fuse mount for testing. But fuse setup was tricky. I'll send a writeup of my test environment to you tomorrow.
Thanks,
Maxim
--
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-mm.org/ .
Don't email: <a href=mailto:"[email protected]"> [email protected] </a>