Received: by 2002:ab2:b82:0:b0:1f3:401:3cfb with SMTP id 2csp437703lqh; Thu, 28 Mar 2024 06:41:18 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCUBnVVBJekLPXyWRQCADPstKKZP5pKf2HIjtvQXPBocgjiHuoPHxFQXtAX7Rr03HJVKkhVngSILBOE9HDywpRLUwH+aqT+Vxp64DIUOLw== X-Google-Smtp-Source: AGHT+IFWSim0fuGFmmz16BUveYsD05juzVACOP0A8rTrtnUApAx507pLsSXz/zg3wEbr5tBqLq84 X-Received: by 2002:a0c:f704:0:b0:696:93f3:7cb3 with SMTP id w4-20020a0cf704000000b0069693f37cb3mr1753881qvn.51.1711633278503; Thu, 28 Mar 2024 06:41:18 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1711633278; cv=pass; d=google.com; s=arc-20160816; b=f7X89hzu4a+sdFBLtlp7yhRJxAAPgKDVRL4Fs/DyEMIa0MvM6TG3MAVQ1e1Qtc5pN9 kopIQruM8ucX8SCWdXuQGAoHyuV4zl+ZvnFpu1hn4QKHlibUtUDfKiNHiEKLxpptD1LT lgtLtK6DNJ7VMAQldY9ctKCY9bD8qy4IiHivxfNpzAujb+w+WDJBFIh3dUJNm9jeukEx PygII/CtT78Ul1zfOsNjeX2JpjO0TjNQ1FSbU/Kis6bK/m/mEQHXcUhYtoVEIq3OeRVf PCSlQvet3rURUzUP9pVUujPpvHClgiVOmUGYBc4jwo/H28eZKqYlM1uTL1docoWqxmR3 rtPg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from; bh=1+LR3anLhgNyfy1DdepUw5hxaFlR/GVCDkeZbq8UPPk=; fh=fIPwRSL7V0j2cHZ0e+9J5K3ctXR4OqYE6glGGMM/7ic=; b=EP6USTRkhlTTgMSwzp0Qd0JgCs9szKI8noK9/2VIeivE31y1WYz3hgTc/5kLAxYVIo GqutBRrcp6CMtdJMFkD7SKuNtIvSv+kYqX8yKfvzvesJuOjvBvtSo15s21Fsoy1B7PwL iOJNq4FXYxAjc/Gk7c7LuHMMJIKmB3t76qL94uob1sPqrVEKBDhvjaqdwkzquxFoR2KG qjd2EzHYn+nO+Hxq2M1eJ7k54gn5e1+Hu34xBgNGkHPq1AKVlpnmLEDhUosbXXKvGTsg HsoAZ62P4ohpL0Q8KuJwCSWT8OVH21n5u0YT9txz+hcLTsLMp/vPPQkHLAF0ehmrQ/id Nu6A==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-122971-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122971-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=QUARANTINE) header.from=huawei.com Return-Path: Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id qj23-20020a056214321700b0069688647dacsi1472131qvb.611.2024.03.28.06.41.18 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Mar 2024 06:41:18 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-122971-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=huawei.com dmarc=pass fromdomain=huawei.com); spf=pass (google.com: domain of linux-kernel+bounces-122971-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-122971-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=QUARANTINE) header.from=huawei.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 3AC2A1C243FF for ; Thu, 28 Mar 2024 13:41:18 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 71373839E4; Thu, 28 Mar 2024 13:40:48 +0000 (UTC) Received: from szxga05-in.huawei.com (szxga05-in.huawei.com [45.249.212.191]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 284EF81ABE; Thu, 28 Mar 2024 13:40:44 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=45.249.212.191 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711633247; cv=none; b=hW+Rge9Em5LR3f+U2nPzx4b/MqTOCSLoic3DfBFM/pt1AQ1WSG2kKvh5x4Gp07Mld1xRnTHbVzjJyWRMVtiq0cOwYhRdgkbsUmq63GTPhlrU7ezxzUKUNa15r+J2M3mZmBj1uA8q8Yo2qD8/ZNh4GFPgDzvP3lxrA2v4HvhcRfU= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1711633247; c=relaxed/simple; bh=OxVEcUmyJUyXbsWx/gP6nZTMqNbohCEm9xfElFGDqcQ=; h=From:To:CC:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version:Content-Type; b=NFgtpnGRftdNm0ruO0kyNzTlBEGPJ1wNe14Dasz54pl6xEU4JXW8YmGRDiidU3DSk/zjNeZLEJUYYcR3AeJFHxV2MkSZBR9jpD1GmiCV+sbLM1iRwFNp2DqYddTtzM1eskPFbfNDtD/bsGCFOgK/WOpZie7vr82E1TPGM9f6qKk= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com; spf=pass smtp.mailfrom=huawei.com; arc=none smtp.client-ip=45.249.212.191 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=quarantine dis=none) header.from=huawei.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=huawei.com Received: from mail.maildlp.com (unknown [172.19.88.234]) by szxga05-in.huawei.com (SkyGuard) with ESMTP id 4V54RG48H3z1GDX7; Thu, 28 Mar 2024 21:40:10 +0800 (CST) Received: from dggpemm500005.china.huawei.com (unknown [7.185.36.74]) by mail.maildlp.com (Postfix) with ESMTPS id A7813140258; Thu, 28 Mar 2024 21:40:42 +0800 (CST) Received: from localhost.localdomain (10.69.192.56) by dggpemm500005.china.huawei.com (7.185.36.74) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.1.2507.35; Thu, 28 Mar 2024 21:40:42 +0800 From: Yunsheng Lin To: , , CC: , , Yunsheng Lin , Alexander Duyck , Andrew Morton , Subject: [PATCH RFC 02/10] mm: page_frag: use initial zero offset for page_frag_alloc_align() Date: Thu, 28 Mar 2024 21:38:31 +0800 Message-ID: <20240328133839.13620-3-linyunsheng@huawei.com> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20240328133839.13620-1-linyunsheng@huawei.com> References: <20240328133839.13620-1-linyunsheng@huawei.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Content-Type: text/plain X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500005.china.huawei.com (7.185.36.74) We are above to use page_frag_alloc_*() API to not just allocate memory for skb->data, but also use them to do the memory allocation for skb frag too. Currently the implementation of page_frag in mm subsystem is running the offset as a countdown rather than count-up value, there may have several advantages to that as mentioned in [1], but it may have some disadvantages, for example, it may disable skb frag coaleasing and more correct cache prefetching We have a trade-off to make in order to have a unified implementation and API for page_frag, so use a initial zero offset in this patch, and the following patch will try to make some optimization to aovid the disadvantages as much as possible. 1. https://lore.kernel.org/all/f4abe71b3439b39d17a6fb2d410180f367cadf5c.camel@gmail.com/ CC: Alexander Duyck Signed-off-by: Yunsheng Lin --- mm/page_frag_alloc.c | 31 ++++++++++++++----------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/mm/page_frag_alloc.c b/mm/page_frag_alloc.c index a0f90ba25200..3e3e88d9af90 100644 --- a/mm/page_frag_alloc.c +++ b/mm/page_frag_alloc.c @@ -67,9 +67,8 @@ void *__page_frag_alloc_align(struct page_frag_cache *nc, unsigned int fragsz, gfp_t gfp_mask, unsigned int align_mask) { - unsigned int size = PAGE_SIZE; + unsigned int size, offset; struct page *page; - int offset; if (unlikely(!nc->va)) { refill: @@ -77,10 +76,6 @@ void *__page_frag_alloc_align(struct page_frag_cache *nc, if (!page) return NULL; -#if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE) - /* if size can vary use size else just use PAGE_SIZE */ - size = nc->size; -#endif /* Even if we own the page, we do not use atomic_set(). * This would break get_page_unless_zero() users. */ @@ -89,11 +84,18 @@ void *__page_frag_alloc_align(struct page_frag_cache *nc, /* reset page count bias and offset to start of new frag */ nc->pfmemalloc = page_is_pfmemalloc(page); nc->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1; - nc->offset = size; + nc->offset = 0; } - offset = nc->offset - fragsz; - if (unlikely(offset < 0)) { +#if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE) + /* if size can vary use size else just use PAGE_SIZE */ + size = nc->size; +#else + size = PAGE_SIZE; +#endif + + offset = ALIGN(nc->offset, -align_mask); + if (unlikely(offset + fragsz > size)) { page = virt_to_page(nc->va); if (!page_ref_sub_and_test(page, nc->pagecnt_bias)) @@ -104,17 +106,13 @@ void *__page_frag_alloc_align(struct page_frag_cache *nc, goto refill; } -#if (PAGE_SIZE < PAGE_FRAG_CACHE_MAX_SIZE) - /* if size can vary use size else just use PAGE_SIZE */ - size = nc->size; -#endif /* OK, page count is 0, we can safely set it */ set_page_count(page, PAGE_FRAG_CACHE_MAX_SIZE + 1); /* reset page count bias and offset to start of new frag */ nc->pagecnt_bias = PAGE_FRAG_CACHE_MAX_SIZE + 1; - offset = size - fragsz; - if (unlikely(offset < 0)) { + offset = 0; + if (unlikely(fragsz > size)) { /* * The caller is trying to allocate a fragment * with fragsz > PAGE_SIZE but the cache isn't big @@ -129,8 +127,7 @@ void *__page_frag_alloc_align(struct page_frag_cache *nc, } nc->pagecnt_bias--; - offset &= align_mask; - nc->offset = offset; + nc->offset = offset + fragsz; return nc->va + offset; } -- 2.33.0