|
13 | 13 | */
|
14 | 14 |
|
15 | 15 | #include <linux/kernel.h>
|
| 16 | +#include <linux/math64.h> |
16 | 17 | #include <linux/export.h>
|
17 | 18 | #include <linux/spinlock.h>
|
18 | 19 | #include <linux/fs.h>
|
@@ -650,6 +651,28 @@ void wb_domain_exit(struct wb_domain *dom)
|
650 | 651 | */
|
651 | 652 | static unsigned int bdi_min_ratio;
|
652 | 653 |
|
| 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 | + |
653 | 676 | static u64 bdi_get_bytes(unsigned int ratio)
|
654 | 677 | {
|
655 | 678 | unsigned long background_thresh;
|
@@ -722,6 +745,20 @@ u64 bdi_get_max_bytes(struct backing_dev_info *bdi)
|
722 | 745 | return bdi_get_bytes(bdi->max_ratio);
|
723 | 746 | }
|
724 | 747 |
|
| 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 | + |
725 | 762 | int bdi_set_strict_limit(struct backing_dev_info *bdi, unsigned int strict_limit)
|
726 | 763 | {
|
727 | 764 | if (strict_limit > 1)
|
|
0 commit comments