Skip to content

Commit cfedef8

Browse files
Matthew Wilcox (Oracle)vijay-suman
authored andcommitted
minmax: add in_range() macro
commit f9bff0e upstream. Patch series "New page table range API", v6. This patchset changes the API used by the MM to set up page table entries. The four APIs are: set_ptes(mm, addr, ptep, pte, nr) update_mmu_cache_range(vma, addr, ptep, nr) flush_dcache_folio(folio) flush_icache_pages(vma, page, nr) flush_dcache_folio() isn't technically new, but no architecture implemented it, so I've done that for them. The old APIs remain around but are mostly implemented by calling the new interfaces. The new APIs are based around setting up N page table entries at once. The N entries belong to the same PMD, the same folio and the same VMA, so ptep++ is a legitimate operation, and locking is taken care of for you. Some architectures can do a better job of it than just a loop, but I have hesitated to make too deep a change to architectures I don't understand well. One thing I have changed in every architecture is that PG_arch_1 is now a per-folio bit instead of a per-page bit when used for dcache clean/dirty tracking. This was something that would have to happen eventually, and it makes sense to do it now rather than iterate over every page involved in a cache flush and figure out if it needs to happen. The point of all this is better performance, and Fengwei Yin has measured improvement on x86. I suspect you'll see improvement on your architecture too. Try the new will-it-scale test mentioned here: https://lore.kernel.org/linux-mm/[email protected]/ You'll need to run it on an XFS filesystem and have CONFIG_TRANSPARENT_HUGEPAGE set. This patchset is the basis for much of the anonymous large folio work being done by Ryan, so it's received quite a lot of testing over the last few months. This patch (of 38): Determine if a value lies within a range more efficiently (subtraction + comparison vs two comparisons and an AND). It also has useful (under some circumstances) behaviour if the range exceeds the maximum value of the type. Convert all the conflicting definitions of in_range() within the kernel; some can use the generic definition while others need their own definition. Link: https://lkml.kernel.org/r/[email protected] Link: https://lkml.kernel.org/r/[email protected] Signed-off-by: Matthew Wilcox (Oracle) <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Eliav Farber <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> (cherry picked from commit 3fe58fa6120522d4d8a18fbc32652f78400b27f6) Signed-off-by: Vijayendra Suman <[email protected]>
1 parent ef650aa commit cfedef8

File tree

15 files changed

+63
-57
lines changed

15 files changed

+63
-57
lines changed

arch/arm/mm/pageattr.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ static int change_page_range(pte_t *ptep, unsigned long addr, void *data)
2525
return 0;
2626
}
2727

28-
static bool in_range(unsigned long start, unsigned long size,
28+
static bool range_in_range(unsigned long start, unsigned long size,
2929
unsigned long range_start, unsigned long range_end)
3030
{
3131
return start >= range_start && start < range_end &&
@@ -46,8 +46,8 @@ static int change_memory_common(unsigned long addr, int numpages,
4646
if (!size)
4747
return 0;
4848

49-
if (!in_range(start, size, MODULES_VADDR, MODULES_END) &&
50-
!in_range(start, size, VMALLOC_START, VMALLOC_END))
49+
if (!range_in_range(start, size, MODULES_VADDR, MODULES_END) &&
50+
!range_in_range(start, size, VMALLOC_START, VMALLOC_END))
5151
return -EINVAL;
5252

5353
data.set_mask = set_mask;

drivers/gpu/drm/arm/display/include/malidp_utils.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ static inline void set_range(struct malidp_range *rg, u32 start, u32 end)
3535
rg->end = end;
3636
}
3737

38-
static inline bool in_range(struct malidp_range *rg, u32 v)
38+
static inline bool malidp_in_range(struct malidp_range *rg, u32 v)
3939
{
4040
return (v >= rg->start) && (v <= rg->end);
4141
}

drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -305,12 +305,12 @@ komeda_layer_check_cfg(struct komeda_layer *layer,
305305
if (komeda_fb_check_src_coords(kfb, src_x, src_y, src_w, src_h))
306306
return -EINVAL;
307307

308-
if (!in_range(&layer->hsize_in, src_w)) {
308+
if (!malidp_in_range(&layer->hsize_in, src_w)) {
309309
DRM_DEBUG_ATOMIC("invalidate src_w %d.\n", src_w);
310310
return -EINVAL;
311311
}
312312

313-
if (!in_range(&layer->vsize_in, src_h)) {
313+
if (!malidp_in_range(&layer->vsize_in, src_h)) {
314314
DRM_DEBUG_ATOMIC("invalidate src_h %d.\n", src_h);
315315
return -EINVAL;
316316
}
@@ -452,14 +452,14 @@ komeda_scaler_check_cfg(struct komeda_scaler *scaler,
452452
hsize_out = dflow->out_w;
453453
vsize_out = dflow->out_h;
454454

455-
if (!in_range(&scaler->hsize, hsize_in) ||
456-
!in_range(&scaler->hsize, hsize_out)) {
455+
if (!malidp_in_range(&scaler->hsize, hsize_in) ||
456+
!malidp_in_range(&scaler->hsize, hsize_out)) {
457457
DRM_DEBUG_ATOMIC("Invalid horizontal sizes");
458458
return -EINVAL;
459459
}
460460

461-
if (!in_range(&scaler->vsize, vsize_in) ||
462-
!in_range(&scaler->vsize, vsize_out)) {
461+
if (!malidp_in_range(&scaler->vsize, vsize_in) ||
462+
!malidp_in_range(&scaler->vsize, vsize_out)) {
463463
DRM_DEBUG_ATOMIC("Invalid vertical sizes");
464464
return -EINVAL;
465465
}
@@ -574,13 +574,13 @@ komeda_splitter_validate(struct komeda_splitter *splitter,
574574
return -EINVAL;
575575
}
576576

577-
if (!in_range(&splitter->hsize, dflow->in_w)) {
577+
if (!malidp_in_range(&splitter->hsize, dflow->in_w)) {
578578
DRM_DEBUG_ATOMIC("split in_w:%d is out of the acceptable range.\n",
579579
dflow->in_w);
580580
return -EINVAL;
581581
}
582582

583-
if (!in_range(&splitter->vsize, dflow->in_h)) {
583+
if (!malidp_in_range(&splitter->vsize, dflow->in_h)) {
584584
DRM_DEBUG_ATOMIC("split in_h: %d exceeds the acceptable range.\n",
585585
dflow->in_h);
586586
return -EINVAL;
@@ -624,13 +624,13 @@ komeda_merger_validate(struct komeda_merger *merger,
624624
return -EINVAL;
625625
}
626626

627-
if (!in_range(&merger->hsize_merged, output->out_w)) {
627+
if (!malidp_in_range(&merger->hsize_merged, output->out_w)) {
628628
DRM_DEBUG_ATOMIC("merged_w: %d is out of the accepted range.\n",
629629
output->out_w);
630630
return -EINVAL;
631631
}
632632

633-
if (!in_range(&merger->vsize_merged, output->out_h)) {
633+
if (!malidp_in_range(&merger->vsize_merged, output->out_h)) {
634634
DRM_DEBUG_ATOMIC("merged_h: %d is out of the accepted range.\n",
635635
output->out_h);
636636
return -EINVAL;
@@ -866,8 +866,8 @@ void komeda_complete_data_flow_cfg(struct komeda_layer *layer,
866866
* input/output range.
867867
*/
868868
if (dflow->en_scaling && scaler)
869-
dflow->en_split = !in_range(&scaler->hsize, dflow->in_w) ||
870-
!in_range(&scaler->hsize, dflow->out_w);
869+
dflow->en_split = !malidp_in_range(&scaler->hsize, dflow->in_w) ||
870+
!malidp_in_range(&scaler->hsize, dflow->out_w);
871871
}
872872

873873
static bool merger_is_available(struct komeda_pipeline *pipe,

drivers/gpu/drm/msm/adreno/a6xx_gmu.c

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -676,12 +676,6 @@ struct block_header {
676676
u32 data[];
677677
};
678678

679-
/* this should be a general kernel helper */
680-
static int in_range(u32 addr, u32 start, u32 size)
681-
{
682-
return addr >= start && addr < start + size;
683-
}
684-
685679
static bool fw_block_mem(struct a6xx_gmu_bo *bo, const struct block_header *blk)
686680
{
687681
if (!in_range(blk->addr, bo->iova, bo->size))

drivers/net/ethernet/chelsio/cxgb3/cxgb3_main.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2135,7 +2135,7 @@ static const struct ethtool_ops cxgb_ethtool_ops = {
21352135
.set_link_ksettings = set_link_ksettings,
21362136
};
21372137

2138-
static int in_range(int val, int lo, int hi)
2138+
static int cxgb_in_range(int val, int lo, int hi)
21392139
{
21402140
return val < 0 || (val <= hi && val >= lo);
21412141
}
@@ -2171,19 +2171,19 @@ static int cxgb_siocdevprivate(struct net_device *dev,
21712171
return -EINVAL;
21722172
if (t.qset_idx >= SGE_QSETS)
21732173
return -EINVAL;
2174-
if (!in_range(t.intr_lat, 0, M_NEWTIMER) ||
2175-
!in_range(t.cong_thres, 0, 255) ||
2176-
!in_range(t.txq_size[0], MIN_TXQ_ENTRIES,
2174+
if (!cxgb_in_range(t.intr_lat, 0, M_NEWTIMER) ||
2175+
!cxgb_in_range(t.cong_thres, 0, 255) ||
2176+
!cxgb_in_range(t.txq_size[0], MIN_TXQ_ENTRIES,
21772177
MAX_TXQ_ENTRIES) ||
2178-
!in_range(t.txq_size[1], MIN_TXQ_ENTRIES,
2178+
!cxgb_in_range(t.txq_size[1], MIN_TXQ_ENTRIES,
21792179
MAX_TXQ_ENTRIES) ||
2180-
!in_range(t.txq_size[2], MIN_CTRL_TXQ_ENTRIES,
2180+
!cxgb_in_range(t.txq_size[2], MIN_CTRL_TXQ_ENTRIES,
21812181
MAX_CTRL_TXQ_ENTRIES) ||
2182-
!in_range(t.fl_size[0], MIN_FL_ENTRIES,
2182+
!cxgb_in_range(t.fl_size[0], MIN_FL_ENTRIES,
21832183
MAX_RX_BUFFERS) ||
2184-
!in_range(t.fl_size[1], MIN_FL_ENTRIES,
2184+
!cxgb_in_range(t.fl_size[1], MIN_FL_ENTRIES,
21852185
MAX_RX_JUMBO_BUFFERS) ||
2186-
!in_range(t.rspq_size, MIN_RSPQ_ENTRIES,
2186+
!cxgb_in_range(t.rspq_size, MIN_RSPQ_ENTRIES,
21872187
MAX_RSPQ_ENTRIES))
21882188
return -EINVAL;
21892189

drivers/virt/acrn/ioreq.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ static bool handle_cf8cfc(struct acrn_vm *vm,
356356
return is_handled;
357357
}
358358

359-
static bool in_range(struct acrn_ioreq_range *range,
359+
static bool acrn_in_range(struct acrn_ioreq_range *range,
360360
struct acrn_io_request *req)
361361
{
362362
bool ret = false;
@@ -394,7 +394,7 @@ static struct acrn_ioreq_client *find_ioreq_client(struct acrn_vm *vm,
394394
list_for_each_entry(client, &vm->ioreq_clients, list) {
395395
read_lock_bh(&client->range_lock);
396396
list_for_each_entry(range, &client->range_list, list) {
397-
if (in_range(range, req)) {
397+
if (acrn_in_range(range, req)) {
398398
found = client;
399399
break;
400400
}

fs/btrfs/misc.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,6 @@
88
#include <linux/math64.h>
99
#include <linux/rbtree.h>
1010

11-
#define in_range(b, first, len) ((b) >= (first) && (b) < (first) + (len))
12-
1311
static inline void cond_wake_up(struct wait_queue_head *wq)
1412
{
1513
/*

fs/ext2/balloc.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,6 @@
3636
*/
3737

3838

39-
#define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1)
40-
4139
struct ext2_group_desc * ext2_get_group_desc(struct super_block * sb,
4240
unsigned int block_group,
4341
struct buffer_head ** bh)

fs/ext4/ext4.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3848,8 +3848,6 @@ static inline void set_bitmap_uptodate(struct buffer_head *bh)
38483848
set_bit(BH_BITMAP_UPTODATE, &(bh)->b_state);
38493849
}
38503850

3851-
#define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1)
3852-
38533851
/* For ioend & aio unwritten conversion wait queues */
38543852
#define EXT4_WQ_HASH_SZ 37
38553853
#define ext4_ioend_wq(v) (&ext4__ioend_wq[((unsigned long)(v)) %\

fs/ufs/util.h

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@
1111
#include <linux/fs.h>
1212
#include "swab.h"
1313

14-
15-
/*
16-
* some useful macros
17-
*/
18-
#define in_range(b,first,len) ((b)>=(first)&&(b)<(first)+(len))
19-
2014
/*
2115
* functions used for retyping
2216
*/

0 commit comments

Comments
 (0)