Skip to content

Commit 1bf27e9

Browse files
Stefan Roeschakpm00
Stefan Roesch
authored andcommitted
mm: add bdi_set_max_bytes() function
This introduces the bdi_set_max_bytes() function. The max_bytes function does not store the max_bytes value. Instead it converts the max_bytes value into the corresponding ratio value. Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Stefan Roesch <[email protected]> Cc: Chris Mason <[email protected]> Cc: Jens Axboe <[email protected]> Signed-off-by: Andrew Morton <[email protected]>
1 parent efc3e6a commit 1bf27e9

File tree

2 files changed

+38
-0
lines changed

2 files changed

+38
-0
lines changed

include/linux/backing-dev.h

+1
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ static inline unsigned long wb_stat_error(void)
108108
u64 bdi_get_max_bytes(struct backing_dev_info *bdi);
109109
int bdi_set_min_ratio(struct backing_dev_info *bdi, unsigned int min_ratio);
110110
int bdi_set_max_ratio(struct backing_dev_info *bdi, unsigned int max_ratio);
111+
int bdi_set_max_bytes(struct backing_dev_info *bdi, u64 max_bytes);
111112
int bdi_set_strict_limit(struct backing_dev_info *bdi, unsigned int strict_limit);
112113

113114
/*

mm/page-writeback.c

+37
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
*/
1414

1515
#include <linux/kernel.h>
16+
#include <linux/math64.h>
1617
#include <linux/export.h>
1718
#include <linux/spinlock.h>
1819
#include <linux/fs.h>
@@ -650,6 +651,28 @@ void wb_domain_exit(struct wb_domain *dom)
650651
*/
651652
static unsigned int bdi_min_ratio;
652653

654+
static int bdi_check_pages_limit(unsigned long pages)
655+
{
656+
unsigned long max_dirty_pages = global_dirtyable_memory();
657+
658+
if (pages > max_dirty_pages)
659+
return -EINVAL;
660+
661+
return 0;
662+
}
663+
664+
static unsigned long bdi_ratio_from_pages(unsigned long pages)
665+
{
666+
unsigned long background_thresh;
667+
unsigned long dirty_thresh;
668+
unsigned long ratio;
669+
670+
global_dirty_limits(&background_thresh, &dirty_thresh);
671+
ratio = div64_u64(pages * 100ULL * BDI_RATIO_SCALE, dirty_thresh);
672+
673+
return ratio;
674+
}
675+
653676
static u64 bdi_get_bytes(unsigned int ratio)
654677
{
655678
unsigned long background_thresh;
@@ -722,6 +745,20 @@ u64 bdi_get_max_bytes(struct backing_dev_info *bdi)
722745
return bdi_get_bytes(bdi->max_ratio);
723746
}
724747

748+
int bdi_set_max_bytes(struct backing_dev_info *bdi, u64 max_bytes)
749+
{
750+
int ret;
751+
unsigned long pages = max_bytes >> PAGE_SHIFT;
752+
unsigned long max_ratio;
753+
754+
ret = bdi_check_pages_limit(pages);
755+
if (ret)
756+
return ret;
757+
758+
max_ratio = bdi_ratio_from_pages(pages);
759+
return __bdi_set_max_ratio(bdi, max_ratio);
760+
}
761+
725762
int bdi_set_strict_limit(struct backing_dev_info *bdi, unsigned int strict_limit)
726763
{
727764
if (strict_limit > 1)

0 commit comments

Comments
 (0)