Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp2210549rwd; Fri, 9 Jun 2023 08:06:45 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4Mp84tCI7v4Gxu+8G2mosgtA4pff0M6fG+3Aa2UpDxTvR8/xpV0w6O/JXZIeW51l+/IHME X-Received: by 2002:a17:902:6b8b:b0:1b1:9d3c:66c9 with SMTP id p11-20020a1709026b8b00b001b19d3c66c9mr1178756plk.5.1686323205504; Fri, 09 Jun 2023 08:06:45 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1686323205; cv=none; d=google.com; s=arc-20160816; b=yK/x5P7Qw+I2dmruUnE3rz94Ed8wFKp8vGHk3+VtMiIG3MCxo+lrh5vtLhdtbatju0 Vnxsha+zYs3eYF6JXPfSuSoeJW3/rhiZYV2T6hl0dUFFegVEVmF8N8JjdUnArgji3k56 +NSGVzJFvbDJKtghMb81Ti3K1/p5NkoZZsbNyiNh30RrFcxoqLhGw5q0Rxoj+GuaJLzU yN+eZUY2y7PrtLgeLA3VEQHwn3gjlM2nZE9XhQs+qQq6d5YmP1vwTaAFslkLO0Sb6H/b awihbSiD+KWVgnaxmXnO3n0KrWcQ5pzi5EVeZnXsTF4X8a137qT+DFZhwuRMKbEr/vOb 1QqQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=XI39v/7BPEpOgTd1ALuJFcrtG1R04Si+uRN4qfzVrdk=; b=wzNiEvm75lu1JLt2EMhvAnMsI1JK421z+SIJZIUMK+4ufBrsqP9Ne9at/4teXxGChn OBNQd/8I2hIancQGqRkPVBk2YHaoPN0eQZ7BsJ8DEPUQ0FbYUIFcgcPhbL93fJ+78imH n41DQa9ZxECSW6IuhTeqb1v/dQqwDP6W8G494+4qBI/cesLWaDDHWpds5a/hy1uxlUC3 YLV2fkfsIp6yfSjc9Z+qUwwv2UAV0EjMSXCZBl9/v34V4nE7IWvuXR6YtZ6gjFIBktm4 9xWhydiv7ikyhqbDk+/BGNr9p0Y4lmVeyNAHY7pu1lSnudfphby2tD+h/xtaY/YwymBA 2RWA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=JOwpClW4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id jh19-20020a170903329300b001a19bd8aa63si2864401plb.36.2023.06.09.08.06.31; Fri, 09 Jun 2023 08:06:45 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20221208 header.b=JOwpClW4; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239386AbjFIO7r (ORCPT + 99 others); Fri, 9 Jun 2023 10:59:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42084 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231709AbjFIO7p (ORCPT ); Fri, 9 Jun 2023 10:59:45 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 23AA818C; Fri, 9 Jun 2023 07:59:44 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id ffacd0b85a97d-30aeee7c8a0so1449607f8f.1; Fri, 09 Jun 2023 07:59:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20221208; t=1686322782; x=1688914782; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=XI39v/7BPEpOgTd1ALuJFcrtG1R04Si+uRN4qfzVrdk=; b=JOwpClW4kxDpACnhAcaLLPR5zm45hHTlHF+6x2FqO0IEX4WGcGlz/H6b2nd6egp8i5 Xpjl+QnSgcNXwBm75739S0XBZosZBOakIOur62fA7AsgKC2t2lmtLA5qHmYPg+MHsSg0 sXCM/AR1/GGQ1uo5j1AKeHIrKOo9aKQQ2CJBzXKnFxzr5aIdkCsaJvDNlXNEXy2IJ5SQ Y4REPYLTCg7528tfe82OtJF2kqvG7diQtak2N6Sdl3ZbZPQ6FLMs3998Ww4nP+QR9Jpf tnZIL5+R7npG3luYHPeM4XOaslpkmATga3Rdmc+0rhUaBoutCQt1BmQ+32Bk0h6ajZFE BY0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1686322782; x=1688914782; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=XI39v/7BPEpOgTd1ALuJFcrtG1R04Si+uRN4qfzVrdk=; b=HF6Fi86aMDCrQp8nD3yrZyvJJsfmR05QS3ICEgtTmbjRwpLLyCQJa/DAF9QHonTBH5 VNj7lXalk/mbohWgBMQTXTCny30oOV4fzKxxf67aSTsxybqsKEnTzLwgrwQaUzzFvKlo Zs6TUjAwLlZTP990675auG7OoJ197ZM8cmoumhwqR20RQTFyxGvzho6VtEoThVOuTtjx TtAeHMlpMfIYQYfxd7ultXA41lbmMSP82lgSjNL7Sf2TSdtbQBgwRVhX6548ZX6OVH90 B7xbLuSHVjOgr6oVQyYM6KXs5U4HCKEo9Uvg+nqaY0pzYv8Xlh5QidkIfThuFoOKSCP2 8+Kg== X-Gm-Message-State: AC+VfDxTEmrv2FvpF63fjT4UGkPtavwnT10yk/dvjp3gb5WnL0Oh+WD5 ioojqgZPG7r3JYa89PzMV90= X-Received: by 2002:a5d:4946:0:b0:30a:f20b:e71 with SMTP id r6-20020a5d4946000000b0030af20b0e71mr1808984wrs.33.1686322781508; Fri, 09 Jun 2023 07:59:41 -0700 (PDT) Received: from localhost.localdomain (host-95-252-166-216.retail.telecomitalia.it. [95.252.166.216]) by smtp.gmail.com with ESMTPSA id x14-20020adfec0e000000b002f6176cc6desm4703705wrn.110.2023.06.09.07.59.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Jun 2023 07:59:40 -0700 (PDT) From: "Fabio M. De Francesco" To: Benjamin LaHaise , Alexander Viro , Christian Brauner , linux-aio@kvack.org, linux-fsdevel@vger.kernel.org, linux-kernel@vger.kernel.org Cc: "Fabio M. De Francesco" , Ira Weiny , Matthew Wilcox Subject: [PATCH] fs/aio: Stop allocating aio rings from HIGHMEM Date: Fri, 9 Jun 2023 16:59:37 +0200 Message-Id: <20230609145937.17610-1-fmdefrancesco@gmail.com> X-Mailer: git-send-email 2.40.1 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org There is no need to allocate aio rings from HIGHMEM because of very little memory needed here. Therefore, use GFP_USER flag in find_or_create_page() and get rid of kmap*() mappings. Cc: Al Viro Cc: Ira Weiny Suggested-by: Matthew Wilcox Signed-off-by: Fabio M. De Francesco --- fs/aio.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-) diff --git a/fs/aio.c b/fs/aio.c index b0b17bd098bb..77e33619de40 100644 --- a/fs/aio.c +++ b/fs/aio.c @@ -530,7 +530,7 @@ static int aio_setup_ring(struct kioctx *ctx, unsigned int nr_events) for (i = 0; i < nr_pages; i++) { struct page *page; page = find_or_create_page(file->f_mapping, - i, GFP_HIGHUSER | __GFP_ZERO); + i, GFP_USER | __GFP_ZERO); if (!page) break; pr_debug("pid(%d) page[%d]->count=%d\n", @@ -571,7 +571,7 @@ static int aio_setup_ring(struct kioctx *ctx, unsigned int nr_events) ctx->user_id = ctx->mmap_base; ctx->nr_events = nr_events; /* trusted copy */ - ring = kmap_atomic(ctx->ring_pages[0]); + ring = page_address(ctx->ring_pages[0]); ring->nr = nr_events; /* user copy */ ring->id = ~0U; ring->head = ring->tail = 0; @@ -579,7 +579,6 @@ static int aio_setup_ring(struct kioctx *ctx, unsigned int nr_events) ring->compat_features = AIO_RING_COMPAT_FEATURES; ring->incompat_features = AIO_RING_INCOMPAT_FEATURES; ring->header_length = sizeof(struct aio_ring); - kunmap_atomic(ring); flush_dcache_page(ctx->ring_pages[0]); return 0; @@ -682,9 +681,8 @@ static int ioctx_add_table(struct kioctx *ctx, struct mm_struct *mm) * we are protected from page migration * changes ring_pages by ->ring_lock. */ - ring = kmap_atomic(ctx->ring_pages[0]); + ring = page_address(ctx->ring_pages[0]); ring->id = ctx->id; - kunmap_atomic(ring); return 0; } @@ -1025,9 +1023,8 @@ static void user_refill_reqs_available(struct kioctx *ctx) * against ctx->completed_events below will make sure we do the * safe/right thing. */ - ring = kmap_atomic(ctx->ring_pages[0]); + ring = page_address(ctx->ring_pages[0]); head = ring->head; - kunmap_atomic(ring); refill_reqs_available(ctx, head, ctx->tail); } @@ -1133,12 +1130,11 @@ static void aio_complete(struct aio_kiocb *iocb) if (++tail >= ctx->nr_events) tail = 0; - ev_page = kmap_atomic(ctx->ring_pages[pos / AIO_EVENTS_PER_PAGE]); + ev_page = page_address(ctx->ring_pages[pos / AIO_EVENTS_PER_PAGE]); event = ev_page + pos % AIO_EVENTS_PER_PAGE; *event = iocb->ki_res; - kunmap_atomic(ev_page); flush_dcache_page(ctx->ring_pages[pos / AIO_EVENTS_PER_PAGE]); pr_debug("%p[%u]: %p: %p %Lx %Lx %Lx\n", ctx, tail, iocb, @@ -1152,10 +1148,9 @@ static void aio_complete(struct aio_kiocb *iocb) ctx->tail = tail; - ring = kmap_atomic(ctx->ring_pages[0]); + ring = page_address(ctx->ring_pages[0]); head = ring->head; ring->tail = tail; - kunmap_atomic(ring); flush_dcache_page(ctx->ring_pages[0]); ctx->completed_events++; @@ -1215,10 +1210,9 @@ static long aio_read_events_ring(struct kioctx *ctx, mutex_lock(&ctx->ring_lock); /* Access to ->ring_pages here is protected by ctx->ring_lock. */ - ring = kmap_atomic(ctx->ring_pages[0]); + ring = page_address(ctx->ring_pages[0]); head = ring->head; tail = ring->tail; - kunmap_atomic(ring); /* * Ensure that once we've read the current tail pointer, that @@ -1250,10 +1244,9 @@ static long aio_read_events_ring(struct kioctx *ctx, avail = min(avail, nr - ret); avail = min_t(long, avail, AIO_EVENTS_PER_PAGE - pos); - ev = kmap(page); + ev = page_address(page); copy_ret = copy_to_user(event + ret, ev + pos, sizeof(*ev) * avail); - kunmap(page); if (unlikely(copy_ret)) { ret = -EFAULT; @@ -1265,9 +1258,8 @@ static long aio_read_events_ring(struct kioctx *ctx, head %= ctx->nr_events; } - ring = kmap_atomic(ctx->ring_pages[0]); + ring = page_address(ctx->ring_pages[0]); ring->head = head; - kunmap_atomic(ring); flush_dcache_page(ctx->ring_pages[0]); pr_debug("%li h%u t%u\n", ret, head, tail); -- 2.40.1