|
27 | 27 | #define MEMFILE_IDX(val) (((val) >> 16) & 0xffff)
|
28 | 28 | #define MEMFILE_ATTR(val) ((val) & 0xffff)
|
29 | 29 |
|
| 30 | +/* Use t->m[0] to encode the offset */ |
| 31 | +#define MEMFILE_OFFSET(t, m0) (((offsetof(t, m0) << 16) | sizeof_field(t, m0))) |
| 32 | +#define MEMFILE_OFFSET0(val) (((val) >> 16) & 0xffff) |
| 33 | +#define MEMFILE_FIELD_SIZE(val) ((val) & 0xffff) |
| 34 | + |
| 35 | +#define DFL_TMPL_SIZE ARRAY_SIZE(hugetlb_dfl_tmpl) |
| 36 | +#define LEGACY_TMPL_SIZE ARRAY_SIZE(hugetlb_legacy_tmpl) |
| 37 | + |
30 | 38 | static struct hugetlb_cgroup *root_h_cgroup __read_mostly;
|
| 39 | +static struct cftype *dfl_files; |
| 40 | +static struct cftype *legacy_files; |
31 | 41 |
|
32 | 42 | static inline struct page_counter *
|
33 | 43 | __hugetlb_cgroup_counter_from_cgroup(struct hugetlb_cgroup *h_cg, int idx,
|
@@ -702,12 +712,142 @@ static int hugetlb_events_local_show(struct seq_file *seq, void *v)
|
702 | 712 | return __hugetlb_events_show(seq, true);
|
703 | 713 | }
|
704 | 714 |
|
| 715 | +static struct cftype hugetlb_dfl_tmpl[] = { |
| 716 | + { |
| 717 | + .name = "max", |
| 718 | + .private = RES_LIMIT, |
| 719 | + .seq_show = hugetlb_cgroup_read_u64_max, |
| 720 | + .write = hugetlb_cgroup_write_dfl, |
| 721 | + .flags = CFTYPE_NOT_ON_ROOT, |
| 722 | + }, |
| 723 | + { |
| 724 | + .name = "rsvd.max", |
| 725 | + .private = RES_RSVD_LIMIT, |
| 726 | + .seq_show = hugetlb_cgroup_read_u64_max, |
| 727 | + .write = hugetlb_cgroup_write_dfl, |
| 728 | + .flags = CFTYPE_NOT_ON_ROOT, |
| 729 | + }, |
| 730 | + { |
| 731 | + .name = "current", |
| 732 | + .private = RES_USAGE, |
| 733 | + .seq_show = hugetlb_cgroup_read_u64_max, |
| 734 | + .flags = CFTYPE_NOT_ON_ROOT, |
| 735 | + }, |
| 736 | + { |
| 737 | + .name = "rsvd.current", |
| 738 | + .private = RES_RSVD_USAGE, |
| 739 | + .seq_show = hugetlb_cgroup_read_u64_max, |
| 740 | + .flags = CFTYPE_NOT_ON_ROOT, |
| 741 | + }, |
| 742 | + { |
| 743 | + .name = "events", |
| 744 | + .seq_show = hugetlb_events_show, |
| 745 | + .file_offset = MEMFILE_OFFSET(struct hugetlb_cgroup, events_file[0]), |
| 746 | + .flags = CFTYPE_NOT_ON_ROOT, |
| 747 | + }, |
| 748 | + { |
| 749 | + .name = "events.local", |
| 750 | + .seq_show = hugetlb_events_local_show, |
| 751 | + .file_offset = MEMFILE_OFFSET(struct hugetlb_cgroup, events_local_file[0]), |
| 752 | + .flags = CFTYPE_NOT_ON_ROOT, |
| 753 | + }, |
| 754 | + { |
| 755 | + .name = "numa_stat", |
| 756 | + .seq_show = hugetlb_cgroup_read_numa_stat, |
| 757 | + .flags = CFTYPE_NOT_ON_ROOT, |
| 758 | + }, |
| 759 | + /* don't need terminator here */ |
| 760 | +}; |
| 761 | + |
| 762 | +static struct cftype hugetlb_legacy_tmpl[] = { |
| 763 | + { |
| 764 | + .name = "limit_in_bytes", |
| 765 | + .private = RES_LIMIT, |
| 766 | + .read_u64 = hugetlb_cgroup_read_u64, |
| 767 | + .write = hugetlb_cgroup_write_legacy, |
| 768 | + }, |
| 769 | + { |
| 770 | + .name = "rsvd.limit_in_bytes", |
| 771 | + .private = RES_RSVD_LIMIT, |
| 772 | + .read_u64 = hugetlb_cgroup_read_u64, |
| 773 | + .write = hugetlb_cgroup_write_legacy, |
| 774 | + }, |
| 775 | + { |
| 776 | + .name = "usage_in_bytes", |
| 777 | + .private = RES_USAGE, |
| 778 | + .read_u64 = hugetlb_cgroup_read_u64, |
| 779 | + }, |
| 780 | + { |
| 781 | + .name = "rsvd.usage_in_bytes", |
| 782 | + .private = RES_RSVD_USAGE, |
| 783 | + .read_u64 = hugetlb_cgroup_read_u64, |
| 784 | + }, |
| 785 | + { |
| 786 | + .name = "max_usage_in_bytes", |
| 787 | + .private = RES_MAX_USAGE, |
| 788 | + .write = hugetlb_cgroup_reset, |
| 789 | + .read_u64 = hugetlb_cgroup_read_u64, |
| 790 | + }, |
| 791 | + { |
| 792 | + .name = "rsvd.max_usage_in_bytes", |
| 793 | + .private = RES_RSVD_MAX_USAGE, |
| 794 | + .write = hugetlb_cgroup_reset, |
| 795 | + .read_u64 = hugetlb_cgroup_read_u64, |
| 796 | + }, |
| 797 | + { |
| 798 | + .name = "failcnt", |
| 799 | + .private = RES_FAILCNT, |
| 800 | + .write = hugetlb_cgroup_reset, |
| 801 | + .read_u64 = hugetlb_cgroup_read_u64, |
| 802 | + }, |
| 803 | + { |
| 804 | + .name = "rsvd.failcnt", |
| 805 | + .private = RES_RSVD_FAILCNT, |
| 806 | + .write = hugetlb_cgroup_reset, |
| 807 | + .read_u64 = hugetlb_cgroup_read_u64, |
| 808 | + }, |
| 809 | + { |
| 810 | + .name = "numa_stat", |
| 811 | + .seq_show = hugetlb_cgroup_read_numa_stat, |
| 812 | + }, |
| 813 | + /* don't need terminator here */ |
| 814 | +}; |
| 815 | + |
| 816 | +static void __init |
| 817 | +hugetlb_cgroup_cfttypes_init(struct hstate *h, struct cftype *cft, |
| 818 | + struct cftype *tmpl, int tmpl_size) |
| 819 | +{ |
| 820 | + char buf[32]; |
| 821 | + int i, idx = hstate_index(h); |
| 822 | + |
| 823 | + /* format the size */ |
| 824 | + mem_fmt(buf, sizeof(buf), huge_page_size(h)); |
| 825 | + |
| 826 | + for (i = 0; i < tmpl_size; cft++, tmpl++, i++) { |
| 827 | + *cft = *tmpl; |
| 828 | + /* rebuild the name */ |
| 829 | + snprintf(cft->name, MAX_CFTYPE_NAME, "%s.%s", buf, tmpl->name); |
| 830 | + /* rebuild the private */ |
| 831 | + cft->private = MEMFILE_PRIVATE(idx, tmpl->private); |
| 832 | + /* rebuild the file_offset */ |
| 833 | + if (tmpl->file_offset) { |
| 834 | + unsigned int offset = tmpl->file_offset; |
| 835 | + |
| 836 | + cft->file_offset = MEMFILE_OFFSET0(offset) + |
| 837 | + MEMFILE_FIELD_SIZE(offset) * idx; |
| 838 | + } |
| 839 | + } |
| 840 | +} |
| 841 | + |
705 | 842 | static void __init __hugetlb_cgroup_file_dfl_init(int idx)
|
706 | 843 | {
|
707 | 844 | char buf[32];
|
708 | 845 | struct cftype *cft;
|
709 | 846 | struct hstate *h = &hstates[idx];
|
710 | 847 |
|
| 848 | + hugetlb_cgroup_cfttypes_init(h, dfl_files + idx * DFL_TMPL_SIZE, |
| 849 | + hugetlb_dfl_tmpl, DFL_TMPL_SIZE); |
| 850 | + |
711 | 851 | /* format the size */
|
712 | 852 | mem_fmt(buf, sizeof(buf), huge_page_size(h));
|
713 | 853 |
|
@@ -779,6 +919,9 @@ static void __init __hugetlb_cgroup_file_legacy_init(int idx)
|
779 | 919 | struct cftype *cft;
|
780 | 920 | struct hstate *h = &hstates[idx];
|
781 | 921 |
|
| 922 | + hugetlb_cgroup_cfttypes_init(h, legacy_files + idx * LEGACY_TMPL_SIZE, |
| 923 | + hugetlb_legacy_tmpl, LEGACY_TMPL_SIZE); |
| 924 | + |
782 | 925 | /* format the size */
|
783 | 926 | mem_fmt(buf, sizeof(buf), huge_page_size(h));
|
784 | 927 |
|
@@ -856,10 +999,23 @@ static void __init __hugetlb_cgroup_file_init(int idx)
|
856 | 999 | __hugetlb_cgroup_file_legacy_init(idx);
|
857 | 1000 | }
|
858 | 1001 |
|
| 1002 | +static void __init __hugetlb_cgroup_file_pre_init(void) |
| 1003 | +{ |
| 1004 | + int cft_count; |
| 1005 | + |
| 1006 | + cft_count = hugetlb_max_hstate * DFL_TMPL_SIZE + 1; /* add terminator */ |
| 1007 | + dfl_files = kcalloc(cft_count, sizeof(struct cftype), GFP_KERNEL); |
| 1008 | + BUG_ON(!dfl_files); |
| 1009 | + cft_count = hugetlb_max_hstate * LEGACY_TMPL_SIZE + 1; /* add terminator */ |
| 1010 | + legacy_files = kcalloc(cft_count, sizeof(struct cftype), GFP_KERNEL); |
| 1011 | + BUG_ON(!legacy_files); |
| 1012 | +} |
| 1013 | + |
859 | 1014 | void __init hugetlb_cgroup_file_init(void)
|
860 | 1015 | {
|
861 | 1016 | struct hstate *h;
|
862 | 1017 |
|
| 1018 | + __hugetlb_cgroup_file_pre_init(); |
863 | 1019 | for_each_hstate(h)
|
864 | 1020 | __hugetlb_cgroup_file_init(hstate_index(h));
|
865 | 1021 | }
|
|
0 commit comments