From patchwork Thu Oct 20 21:53:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Doug Berger X-Patchwork-Id: 6430 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp340165wrr; Thu, 20 Oct 2022 14:59:59 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7ZRqlV92eELs2JdnDCU54GvarRADR4P87jw5VSua9yNKaS/1qr2WkgQaLBZ2h1wA661q6F X-Received: by 2002:a63:5703:0:b0:439:14a8:52b with SMTP id l3-20020a635703000000b0043914a8052bmr12953360pgb.500.1666303199519; Thu, 20 Oct 2022 14:59:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666303199; cv=none; d=google.com; s=arc-20160816; b=mM9Y7GqtGipEp3anmyC6U/G6EiO19YqF+sZmlXYZLyA+ReEaMzh3ve2lXPu2lT2ASt R2SXk+V4pHZhWOV2R3tTMct2C1uOElwAXainDCxd7Ro6b5aOJTvLbxud78gmS5lIGc5G KdIrh4488NVpI9fSUirzL55hT+Sb4m4VL+hz6Ek/lQ0dhyAETa3BQk6GpN12BXwFuB1u GmJMqbXQ99ITBkdS/UuWRUHNsJNNp4G/rm/QSw6ZMkwLWEfO75JvPpxDw6e8lXh/Nkhk 0wgBbHWhBY277Kr/VoD7gTsF8sH8VkrLUWEuVIgKMa7mY7c7olKSuAh7D8fUJxUQqM/G nrlQ== 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 :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=k0ZvpnVNYZiRg/rCuSdzxC9eb6lzs9TieDFdQySZsn8=; b=x8/4MB3gw4jK9AWw8SELoZl7fU+kJq+DttgVNKg9n7Pg5CEfZ1TJvF7mh4qY+KnV71 HaS4hv9okZiDtqMEgEFNf8WzPVVRDWlxa2jxPJ89DQcC2BKe2tjMKG3Qlfq5q9EtNL8r VTxk+QOjiX/KeHpknQ4bX8+pNcKRoAUFUyDAZwMy28XpiXVJGW9icP3sjyCBI5oaKb4r cQ2n83/3JTGfco2o7sC0eQGNqcUFng0VgccPQvKneJwgtRLv4IJYr4QTf8pXhnf7Rj79 xQqNdD7Nlh9rCbAVm6Xb4BT9mXeh6EvIBeTKQi6/FYJB//XVsmSM7OpR0ZQwkUcFOqDg gQXA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gmail.com header.s=20210112 header.b=SZ1PlrYO; 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: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id z4-20020a6552c4000000b0046439853c62si23163565pgp.127.2022.10.20.14.59.46; Thu, 20 Oct 2022 14:59:59 -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=20210112 header.b=SZ1PlrYO; 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 S229908AbiJTVzS (ORCPT + 99 others); Thu, 20 Oct 2022 17:55:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54356 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230086AbiJTVyx (ORCPT ); Thu, 20 Oct 2022 17:54:53 -0400 Received: from mail-qv1-xf2f.google.com (mail-qv1-xf2f.google.com [IPv6:2607:f8b0:4864:20::f2f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CBBF05FCA; Thu, 20 Oct 2022 14:54:40 -0700 (PDT) Received: by mail-qv1-xf2f.google.com with SMTP id x15so640365qvp.1; Thu, 20 Oct 2022 14:54:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=k0ZvpnVNYZiRg/rCuSdzxC9eb6lzs9TieDFdQySZsn8=; b=SZ1PlrYOPpSqmq/vLnLZafqj76vcgQtuklt87DwVjrckcKo++SoYbWCoXH2RuEmcb6 4y4tJhiFfNsKAYGCDqNldMQv8ggfF9el1/DuGHGyFTTgGJTgBB1ub2t8TJn/8VQ/0njh x9PBzyecXTaH7sPHGenWV53OQv2MF6VIv7XIRqYd6awOmsAXwfizyl7Pvu/dtb12NoEI FmlTxSQ26E38t9VXc438mbDPBM+Nsfx1gqnxiKl0224bwHFJKJ36YENdqiT+aCbkxIGU QeFvaN4zOD3HePcbtw0ZaU1yZSvLexZNzQIPkdE25F5wKPOiXAjcD1OSAUZXG39Xan4S LqVQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=k0ZvpnVNYZiRg/rCuSdzxC9eb6lzs9TieDFdQySZsn8=; b=S4uFdewn95nKOBfbiI6JPdHxZ6TaB3LIdEoxikXMwVjzoaX9vOdeNeHBKge5q++Bvy RQSMWzqfQSsp52Xx/ztM+JGrKnVBLhQASGHysyOL0A1BoPiOy0yVTZeULNKjbrwGO+Zm 06ibPrp3imh0NVKcANbXyCNkjQvXrLZO8mUlduiAxlgcqIKokZSr5qGrL8Slq4ujobUy Co1xms4BuijitPMxcS1w8TzWZwxj/1W72dU0OicVvnf8iopLZTydy+CT2LR/LUMEmYsK NL7k/4kvLpVExK3R39gxBLr+RDW47A8swhSRpJ08Ux6BjAJVgrTvfE3JNmCzZ0rX2n2f 5eUg== X-Gm-Message-State: ACrzQf1BF3pmwIx8hf7H8MsXWFbMYMHok+xqoG97PAIMj7FzHjdFqFnp tuGWHTzyUVpQAprFHrpCVOQ= X-Received: by 2002:a05:6214:29ef:b0:4b4:5d8c:637c with SMTP id jv15-20020a05621429ef00b004b45d8c637cmr13527095qvb.77.1666302879221; Thu, 20 Oct 2022 14:54:39 -0700 (PDT) Received: from stbirv-lnx-3.igp.broadcom.net ([192.19.223.252]) by smtp.gmail.com with ESMTPSA id bj41-20020a05620a192900b006bb29d932e1sm8121067qkb.105.2022.10.20.14.54.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Oct 2022 14:54:38 -0700 (PDT) From: Doug Berger To: Andrew Morton Cc: Jonathan Corbet , Mike Rapoport , Borislav Petkov , "Paul E. McKenney" , Neeraj Upadhyay , Randy Dunlap , Damien Le Moal , Muchun Song , Vlastimil Babka , Johannes Weiner , Michal Hocko , KOSAKI Motohiro , Mel Gorman , Mike Kravetz , Florian Fainelli , David Hildenbrand , Oscar Salvador , Joonsoo Kim , linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, Doug Berger Subject: [PATCH v3 6/9] memblock: introduce MEMBLOCK_MOVABLE flag Date: Thu, 20 Oct 2022 14:53:15 -0700 Message-Id: <20221020215318.4193269-7-opendmb@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221020215318.4193269-1-opendmb@gmail.com> References: <20221020215318.4193269-1-opendmb@gmail.com> MIME-Version: 1.0 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 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747245543663963094?= X-GMAIL-MSGID: =?utf-8?q?1747245543663963094?= The MEMBLOCK_MOVABLE flag is introduced to designate a memblock as only supporting movable allocations by the page allocator. Signed-off-by: Doug Berger --- include/linux/memblock.h | 8 ++++++++ mm/memblock.c | 24 ++++++++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/include/linux/memblock.h b/include/linux/memblock.h index 50ad19662a32..8eb3ca32dfa7 100644 --- a/include/linux/memblock.h +++ b/include/linux/memblock.h @@ -47,6 +47,7 @@ enum memblock_flags { MEMBLOCK_MIRROR = 0x2, /* mirrored region */ MEMBLOCK_NOMAP = 0x4, /* don't add to kernel direct mapping */ MEMBLOCK_DRIVER_MANAGED = 0x8, /* always detected via a driver */ + MEMBLOCK_MOVABLE = 0x10, /* designated movable block */ }; /** @@ -125,6 +126,8 @@ int memblock_clear_hotplug(phys_addr_t base, phys_addr_t size); int memblock_mark_mirror(phys_addr_t base, phys_addr_t size); int memblock_mark_nomap(phys_addr_t base, phys_addr_t size); int memblock_clear_nomap(phys_addr_t base, phys_addr_t size); +int memblock_mark_movable(phys_addr_t base, phys_addr_t size); +int memblock_clear_movable(phys_addr_t base, phys_addr_t size); void memblock_free_all(void); void memblock_free(void *ptr, size_t size); @@ -265,6 +268,11 @@ static inline bool memblock_is_driver_managed(struct memblock_region *m) return m->flags & MEMBLOCK_DRIVER_MANAGED; } +static inline bool memblock_is_movable(struct memblock_region *m) +{ + return m->flags & MEMBLOCK_MOVABLE; +} + int memblock_search_pfn_nid(unsigned long pfn, unsigned long *start_pfn, unsigned long *end_pfn); void __next_mem_pfn_range(int *idx, int nid, unsigned long *out_start_pfn, diff --git a/mm/memblock.c b/mm/memblock.c index 511d4783dcf1..46a4deb07d92 100644 --- a/mm/memblock.c +++ b/mm/memblock.c @@ -979,6 +979,30 @@ int __init_memblock memblock_clear_nomap(phys_addr_t base, phys_addr_t size) return memblock_setclr_flag(base, size, 0, MEMBLOCK_NOMAP); } +/** + * memblock_mark_movable - Mark designated movable block with MEMBLOCK_MOVABLE. + * @base: the base phys addr of the region + * @size: the size of the region + * + * Return: 0 on success, -errno on failure. + */ +int __init_memblock memblock_mark_movable(phys_addr_t base, phys_addr_t size) +{ + return memblock_setclr_flag(base, size, 1, MEMBLOCK_MOVABLE); +} + +/** + * memblock_clear_movable - Clear flag MEMBLOCK_MOVABLE for a specified region. + * @base: the base phys addr of the region + * @size: the size of the region + * + * Return: 0 on success, -errno on failure. + */ +int __init_memblock memblock_clear_movable(phys_addr_t base, phys_addr_t size) +{ + return memblock_setclr_flag(base, size, 0, MEMBLOCK_MOVABLE); +} + static bool should_skip_region(struct memblock_type *type, struct memblock_region *m, int nid, int flags)