Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp991905iob; Fri, 13 May 2022 18:52:33 -0700 (PDT) X-Google-Smtp-Source: ABdhPJz59U/E1m3nOvoTHUGsmGvCX3tJ17GPM7mo6RXBXdZK3zoWB2g6PMxPVj8y1XzYKznwH8Xg X-Received: by 2002:a7b:c202:0:b0:394:1e7d:af44 with SMTP id x2-20020a7bc202000000b003941e7daf44mr6850139wmi.139.1652493153476; Fri, 13 May 2022 18:52:33 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1652493153; cv=none; d=google.com; s=arc-20160816; b=Btw31trkppQH+rfAzqhLlrMqgSK3ucayHTjMUPQjls24D1oWsH+KsULVYpjM/QP9we XJHedLlu87rafClnOfPfzv58eUmCf0yAppkdWnuOKxCfjE6kPUlPGIB1a2r7qaaKhPyY TtEuFKPKAq93Al/7Awy3Apz+7jOBX/sLLZtkVOYAVx+qz+fHFiOEbVmCim8QCHR1loYa NR7GrULUGSbaNRO4N7yGjVOsP6DyedcKCd+LGqS5mQRMV1NxET4jlHEafZRw8vKeoaOM VQJVDKXIzjCW+vn+tQnDQ5m2Yb33OWPE8ZWTvP/tNJYpQo0Zft3j0rrTkolO9SffpP20 JddA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:sender:dkim-signature; bh=wE4fM5nUVTqmCaQXZXpkbCTeK+S09eBBfW0cqX/Y51o=; b=FREoPqd7BDt9RCoo6qjeGw/F2p31z3m9MfoYi7UAhmuE0nxFWjEsnFYZXkawGxsq7+ Nv61DCriznG0Ajxb6tgyZQpLeR2OqJp4pDU5G9zeRroXgQkG5ojUr4/uz1u8BW+IO2ec JtzxgDRyo/PyWo7gnWSNE/uB2OleK7de4SeHId5TNiJpcHVqAEbDDYPcb3L5UqaRu5Gn Ul2NgkIFCYDKWpAPtalon9f1lgqZu1UA1oSu9O/C8OdVfId05E/pw6DcyIkDdGzwcbzM gHA20uRSnHiOJMG06QVTP95J7Q3gM0vgfwfYSMr7VJupQK6S2VlR/E6njCDGhqroSJYd CT6w== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=brQstMvv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [2620:137:e000::1:18]) by mx.google.com with ESMTPS id d8-20020a05600c34c800b003940660a754si7322608wmq.83.2022.05.13.18.52.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 13 May 2022 18:52:33 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) client-ip=2620:137:e000::1:18; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=brQstMvv; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id EA42D4525F4; Fri, 13 May 2022 17:16:16 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1349345AbiEKX2Q (ORCPT + 99 others); Wed, 11 May 2022 19:28:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56270 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1349327AbiEKX2F (ORCPT ); Wed, 11 May 2022 19:28:05 -0400 Received: from mail-pf1-x429.google.com (mail-pf1-x429.google.com [IPv6:2607:f8b0:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AF82E1F15B2 for ; Wed, 11 May 2022 16:28:04 -0700 (PDT) Received: by mail-pf1-x429.google.com with SMTP id j6so3229036pfe.13 for ; Wed, 11 May 2022 16:28:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=sender:date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=wE4fM5nUVTqmCaQXZXpkbCTeK+S09eBBfW0cqX/Y51o=; b=brQstMvvcVFVEOo7KS1GQjsrPzJKSSMUIv8IJ6jrjVfyKj6in5WrTNF3lzQFg2y6Wi a44TJXIeuy5CLKYJAI80ISkbM5pXFjt19COwyCysbPRExE6la0Hax22Pi87Nd2Hf/AnX HkXNj5aMYNujgLAbHL8jbcpRsJ95wrz0PEwnb086b7x2njW78b/yWJItesR/1WxYrzGy nVQiCOb0ppp0nIVaTxstVk00lcy/O9JbUffqXll8YFKx+EaInMQzy9Iittv1cb5ANHQk d5BLkn5n9Z8Eikajk8T1JOEuR6oxi7zizVjIQAoAEhlczm7XGK2UczP0fmBV2KRcSBL3 Rwjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:sender:date:from:to:cc:subject:message-id :references:mime-version:content-disposition:in-reply-to; bh=wE4fM5nUVTqmCaQXZXpkbCTeK+S09eBBfW0cqX/Y51o=; b=xopgJb6OroG4x91U4HXnyIhwN0rOx8vnoCK4Gpwq1P2HIKnXeOsH3FGztbKOSbd09l 3rzkKGcgFVCuqH7g9SwVhTH7KeA2Nv/WL/lC6AQYKg+iH3TWHRC0FPVneWfDhydWD6hC OuEJMfRBUyYgP/cMJBlfDApSPXjIw8mSTW605hOSOmyEwIO/MoKFD0cyKZL26gmGmn7q yLm3x/K9tpJdtXhlZyEuFlEHHSBIsbaFj5wZQT1SL+6VHU9SA1XCsJUMAYG5m4VOmg3X /pEySMuN7QDCpHeR7jt+vLYitoReWNbz0ls3yDCoj7x9aovgCZP2vhVYd9an+XqpQy3y zXJw== X-Gm-Message-State: AOAM530p0HL2tXtyRmapmigV1sLNImSklYBg1wFOJAc8plnEa/7PvGq6 lbitkX1Pv0LwHpm4BcpHVkg= X-Received: by 2002:a63:4b42:0:b0:3c6:3c00:2608 with SMTP id k2-20020a634b42000000b003c63c002608mr22802358pgl.231.1652311684197; Wed, 11 May 2022 16:28:04 -0700 (PDT) Received: from google.com ([2620:15c:211:201:69ef:9c87:7816:4f74]) by smtp.gmail.com with ESMTPSA id u17-20020a170903125100b0015e8d4eb21asm2466715plh.100.2022.05.11.16.28.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 11 May 2022 16:28:03 -0700 (PDT) Sender: Minchan Kim Date: Wed, 11 May 2022 16:28:02 -0700 From: Minchan Kim To: John Hubbard Cc: Andrew Morton , linux-mm , LKML , "Paul E . McKenney" , John Dias , David Hildenbrand Subject: Re: [PATCH v4] mm: fix is_pinnable_page against on cma page Message-ID: References: <2ffa7670-04ea-bb28-28f8-93a9b9eea7e8@nvidia.com> <54b5d177-f2f4-cef2-3a68-cd3b0b276f86@nvidia.com> <8f083802-7ab0-15ec-b37d-bc9471eea0b1@nvidia.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE, T_SCC_BODY_TEXT_LINE autolearn=no 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 On Wed, May 11, 2022 at 04:15:17PM -0700, Minchan Kim wrote: > On Wed, May 11, 2022 at 04:13:10PM -0700, John Hubbard wrote: > > On 5/11/22 16:08, Minchan Kim wrote: > > > > OK, so the code checks the wrong item each time. But the code really > > > > only needs to know "is either _CMA or _ISOLATE set?". And so you > > > > > > Yes. > > > > > > > can just sidestep the entire question by writing it like this: > > > > > > > > int mt = get_pageblock_migratetype(page); > > > > > > > > if (mt & (MIGRATE_ISOLATE | MIGRATE_CMA)) > > > > return false; > > > > > > I am confused. Isn't it same question? > > > > > > set_pageblock_migratetype(MIGRATE_ISOLATE) > > > if (get_pageblock_migrate(page) & MIGRATE_CMA) > > > > > > set_pageblock_migratetype(MIGRATE_CMA) > > > > > > if (get_pageblock_migrate(page) & MIGRATE_ISOLATE) > > > > Well no, because the "&" operation is a single operation on the CPU, and > > isn't going to get split up like that. > > Oh, if that's true, yeah, I could live with it. > > Thanks, let me post next revision with commenting about that. This is delta to confirm before posting next revision. Are you okay with this one? diff --git a/include/linux/mm.h b/include/linux/mm.h index cbf79eb790e0..7b2df6780552 100644 --- a/include/linux/mm.h +++ b/include/linux/mm.h @@ -1626,14 +1626,14 @@ static inline bool page_needs_cow_for_dma(struct vm_area_struct *vma, static inline bool is_pinnable_page(struct page *page) { #ifdef CONFIG_CMA + int mt = get_pageblock_migratetype(page); + /* - * use volatile to use local variable mt instead of - * refetching mt value. + * "&" operation would prevent compiler split up + * get_pageblock_migratetype two times for each + * condition check: refetching mt value two times. */ - int __mt = get_pageblock_migratetype(page); - int mt = __READ_ONCE(__mt); - - if (mt == MIGRATE_CMA || mt == MIGRATE_ISOLATE) + if (mt & (MIGRATE_ISOLATE | MIGRATE_CMA)) return false; #endif