Skip to content

Commit f9bff0e

Browse files
Matthew Wilcox (Oracle)akpm00
authored andcommitted
minmax: add in_range() macro
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]>
1 parent f82e6bf commit f9bff0e

File tree

16 files changed

+65
-59
lines changed

16 files changed

+65
-59
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 &&
@@ -63,8 +63,8 @@ static int change_memory_common(unsigned long addr, int numpages,
6363
if (!size)
6464
return 0;
6565

66-
if (!in_range(start, size, MODULES_VADDR, MODULES_END) &&
67-
!in_range(start, size, VMALLOC_START, VMALLOC_END))
66+
if (!range_in_range(start, size, MODULES_VADDR, MODULES_END) &&
67+
!range_in_range(start, size, VMALLOC_START, VMALLOC_END))
6868
return -EINVAL;
6969

7070
return __change_memory_common(start, size, set_mask, clear_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
@@ -2126,7 +2126,7 @@ static const struct ethtool_ops cxgb_ethtool_ops = {
21262126
.set_link_ksettings = set_link_ksettings,
21272127
};
21282128

2129-
static int in_range(int val, int lo, int hi)
2129+
static int cxgb_in_range(int val, int lo, int hi)
21302130
{
21312131
return val < 0 || (val <= hi && val >= lo);
21322132
}
@@ -2162,19 +2162,19 @@ static int cxgb_siocdevprivate(struct net_device *dev,
21622162
return -EINVAL;
21632163
if (t.qset_idx >= SGE_QSETS)
21642164
return -EINVAL;
2165-
if (!in_range(t.intr_lat, 0, M_NEWTIMER) ||
2166-
!in_range(t.cong_thres, 0, 255) ||
2167-
!in_range(t.txq_size[0], MIN_TXQ_ENTRIES,
2165+
if (!cxgb_in_range(t.intr_lat, 0, M_NEWTIMER) ||
2166+
!cxgb_in_range(t.cong_thres, 0, 255) ||
2167+
!cxgb_in_range(t.txq_size[0], MIN_TXQ_ENTRIES,
21682168
MAX_TXQ_ENTRIES) ||
2169-
!in_range(t.txq_size[1], MIN_TXQ_ENTRIES,
2169+
!cxgb_in_range(t.txq_size[1], MIN_TXQ_ENTRIES,
21702170
MAX_TXQ_ENTRIES) ||
2171-
!in_range(t.txq_size[2], MIN_CTRL_TXQ_ENTRIES,
2171+
!cxgb_in_range(t.txq_size[2], MIN_CTRL_TXQ_ENTRIES,
21722172
MAX_CTRL_TXQ_ENTRIES) ||
2173-
!in_range(t.fl_size[0], MIN_FL_ENTRIES,
2173+
!cxgb_in_range(t.fl_size[0], MIN_FL_ENTRIES,
21742174
MAX_RX_BUFFERS) ||
2175-
!in_range(t.fl_size[1], MIN_FL_ENTRIES,
2175+
!cxgb_in_range(t.fl_size[1], MIN_FL_ENTRIES,
21762176
MAX_RX_JUMBO_BUFFERS) ||
2177-
!in_range(t.rspq_size, MIN_RSPQ_ENTRIES,
2177+
!cxgb_in_range(t.rspq_size, MIN_RSPQ_ENTRIES,
21782178
MAX_RSPQ_ENTRIES))
21792179
return -EINVAL;
21802180

drivers/virt/acrn/ioreq.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ static bool handle_cf8cfc(struct acrn_vm *vm,
351351
return is_handled;
352352
}
353353

354-
static bool in_range(struct acrn_ioreq_range *range,
354+
static bool acrn_in_range(struct acrn_ioreq_range *range,
355355
struct acrn_io_request *req)
356356
{
357357
bool ret = false;
@@ -389,7 +389,7 @@ static struct acrn_ioreq_client *find_ioreq_client(struct acrn_vm *vm,
389389
list_for_each_entry(client, &vm->ioreq_clients, list) {
390390
read_lock_bh(&client->range_lock);
391391
list_for_each_entry(range, &client->range_list, list) {
392-
if (in_range(range, req)) {
392+
if (acrn_in_range(range, req)) {
393393
found = client;
394394
break;
395395
}

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
/*
1412
* Enumerate bits using enum autoincrement. Define the @name as the n-th bit.
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
@@ -3774,8 +3774,6 @@ static inline void set_bitmap_uptodate(struct buffer_head *bh)
37743774
set_bit(BH_BITMAP_UPTODATE, &(bh)->b_state);
37753775
}
37763776

3777-
#define in_range(b, first, len) ((b) >= (first) && (b) <= (first) + (len) - 1)
3778-
37793777
/* For ioend & aio unwritten conversion wait queues */
37803778
#define EXT4_WQ_HASH_SZ 37
37813779
#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)