From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id A954AC001B0 for ; Wed, 12 Jul 2023 19:06:28 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 20B3C8D0008; Wed, 12 Jul 2023 15:06:28 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1BB4E8D0002; Wed, 12 Jul 2023 15:06:28 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 08C258D0008; Wed, 12 Jul 2023 15:06:28 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id DE4338D0002 for ; Wed, 12 Jul 2023 15:06:23 -0400 (EDT) Received: from smtpin09.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay05.hostedemail.com (Postfix) with ESMTP id 4713B4035E for ; Wed, 12 Jul 2023 19:06:21 +0000 (UTC) X-FDA: 81003890562.09.7FBD4BB Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by imf24.hostedemail.com (Postfix) with ESMTP id C168E180020 for ; Wed, 12 Jul 2023 19:06:13 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HrKVprYS; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1689188774; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=TH8kSVdw6te9fZYouICsYG10z251roU+ykSRmjAwUKo=; b=hW/fu8Y9czyi+YjPpEhztoFTLVNan1Z9q/f1tam7P1Elt/g24GfXAYIzTl5ghTSBjQ6HQC sJz+UNbbWNJ/ogdv1tvv0c9mP0uMYfsj9S0Y4q1sVaxdWdrCoGZ0w2SEbHDQqTJPCs865g hbLk+xZB/ECy8M3V1V2B3vwqNu487nI= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=pass header.d=redhat.com header.s=mimecast20190719 header.b=HrKVprYS; dmarc=pass (policy=none) header.from=redhat.com; spf=pass (imf24.hostedemail.com: domain of david@redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=david@redhat.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1689188774; a=rsa-sha256; cv=none; b=ZnWrAEsHRf/JuvHQ5hizQRa9ZeDK3BDSlBgnhJfXdaVvvOEgvBZOP/qqMAFr4qRM4r6Z+L 1K/+0T+34FJH1IjM7d5Iq+7Pq0eP3vLreCOl3vu945eaO958N3gk0ytdvzJNQta4k4Pj36 MxUPrP0pdwwSgHN08kZAwDgu1kYfHmM= DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1689188772; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=TH8kSVdw6te9fZYouICsYG10z251roU+ykSRmjAwUKo=; b=HrKVprYSFewBDyhCJHb7c+tDBrAN8ueEqJ3CabZ0z/O3VUhp8bHgzv8b7fwhcB0Kdz0Xkz Vhl3DInMXqNt7vhzzmv5Kk+HuP/8BMmcW6a2QfapMuCUJpNP8JUV/5w/9yJRqdm7a2Gt3f jvfDgzE3qAQA0LVcDcUaAtHrT+GadbM= Received: from mail-wm1-f72.google.com (mail-wm1-f72.google.com [209.85.128.72]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-232-wmi4JxYDPruTROibknK1AA-1; Wed, 12 Jul 2023 15:06:10 -0400 X-MC-Unique: wmi4JxYDPruTROibknK1AA-1 Received: by mail-wm1-f72.google.com with SMTP id 5b1f17b1804b1-3fb416d7731so42633905e9.2 for ; Wed, 12 Jul 2023 12:06:10 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1689188770; x=1691780770; h=content-transfer-encoding:in-reply-to:subject:organization:from :references:cc:to:content-language:user-agent:mime-version:date :message-id:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=TH8kSVdw6te9fZYouICsYG10z251roU+ykSRmjAwUKo=; b=lg3dFqUmzNvkb3V4jYp+u75eSDW5VHu5EtY7J0GvPCcnIHvcJ2jvQb7vgsCWUVLArL Zggt8pRnszB9aTUi4bU32dNePAoXwbJN0owT05eOrvUbgbDzBipyOeOLdFRGbQVBmlIX ajkz+BrisW3y3PhqkVrtDmu/J31aDZXEVK8oHX+M8E5ASo0SrQPnsEMj7hJ6dDRdKrRg 23+80I5YyrTFcj51JKA7zzthnX6t/U8IXeUZPRmfzW4UVNlQCl37V80lxYwH+UCIrhQW 0hl6d5Cob5hl85imUfeXnBpEcX/A25ZdTFqHMVjB5jiWsXDenaL9giJAt88/uos2jFBu nbHQ== X-Gm-Message-State: ABy/qLbEgRWb1+2WIHLe/IbqNV1fcB2m/7ETdBe91a746dEt+zKrj8fm aKoAvNRfIMkWujWh3CurdZ26bQYxeHt5yTIudd74Z3AiN5OKTLLfRHdjYbYXsaaDU8NgzJpiWvC AG7uao1CO+KQ= X-Received: by 2002:a05:600c:3644:b0:3fc:627:ea31 with SMTP id y4-20020a05600c364400b003fc0627ea31mr13170856wmq.38.1689188769704; Wed, 12 Jul 2023 12:06:09 -0700 (PDT) X-Google-Smtp-Source: APBJJlEJAY+2GhS4XJclXcXEd8YQMKAMPvGWx2HjQXRKwdVt2URQdeCbd85XkzInZ39IOwfgHTAaNA== X-Received: by 2002:a05:600c:3644:b0:3fc:627:ea31 with SMTP id y4-20020a05600c364400b003fc0627ea31mr13170839wmq.38.1689188769283; Wed, 12 Jul 2023 12:06:09 -0700 (PDT) Received: from ?IPV6:2003:cb:c707:3700:3eea:ace6:5bde:4478? (p200300cbc70737003eeaace65bde4478.dip0.t-ipconnect.de. [2003:cb:c707:3700:3eea:ace6:5bde:4478]) by smtp.gmail.com with ESMTPSA id q10-20020adfdfca000000b003144b95e1ecsm5745648wrn.93.2023.07.12.12.06.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 12 Jul 2023 12:06:08 -0700 (PDT) Message-ID: <5b4dcee6-c72f-103a-dd7b-b829f5be948b@redhat.com> Date: Wed, 12 Jul 2023 21:06:07 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.12.0 To: "Aneesh Kumar K.V" , linux-mm@kvack.org, akpm@linux-foundation.org, mpe@ellerman.id.au, linuxppc-dev@lists.ozlabs.org, npiggin@gmail.com, christophe.leroy@csgroup.eu Cc: Oscar Salvador , Michal Hocko , Vishal Verma References: <20230711044834.72809-1-aneesh.kumar@linux.ibm.com> <20230711044834.72809-5-aneesh.kumar@linux.ibm.com> <57dd0568-ee56-ff8d-3ba3-a9089a2ab386@redhat.com> <87wmz56xyh.fsf@linux.ibm.com> From: David Hildenbrand Organization: Red Hat Subject: Re: [PATCH v3 4/7] mm/hotplug: Allow pageblock alignment via altmap reservation In-Reply-To: <87wmz56xyh.fsf@linux.ibm.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Rspam-User: X-Rspamd-Server: rspam12 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YMb9bgsoD+8RiYID2z5al07bw+C65mbnh/9PWNbW/N9w8jO5D0gTvTHmK+svLi/a00XkBWXwBOqzcdOtAW9sFfGGSqPWlGcmfLuYdOTrRHDPc1sJ/uODrAe8ytGNgAYhKM4ZjVIZ7NzziL2o3IBUbwIapMmrof7lS17nPhLGmBoXEw5p9y0atgdDm+jAZQLK4j/mA0bxP9w5HxoAEXdtIYMl0+LAsTON95U/+OTuqOeIO8qDKY/IYsYAnnfXCILT7YuEnDnUFhwoo8zqjucRVRVW7RYLFGqvzYLUR7xRHoxPxkEZMgSm4V6ZUA== X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 12.07.23 15:50, Aneesh Kumar K.V wrote: > David Hildenbrand writes: > >> On 12.07.23 05:16, Aneesh Kumar K V wrote: >>> On 7/11/23 10:49 PM, David Hildenbrand wrote: >>>> On 11.07.23 06:48, Aneesh Kumar K.V wrote: >>>>> Add a new kconfig option that can be selected if we want to allow >>>>> pageblock alignment by reserving pages in the vmemmap altmap area. >>>>> This implies we will be reserving some pages for every memoryblock >>>>> This also allows the memmap on memory feature to be widely useful >>>>> with different memory block size values. >>>> >>>> "reserving pages" is a nice way of saying "wasting memory". :) Let's spell that out. >>>> >>>> I think we have to find a better name for this, and I think we should have a toggle similar to memory_hotplug.memmap_on_memory. This should be an admin decision, not some kernel config option. >>>> >>>> >>>> memory_hotplug.force_memmap_on_memory >>>> >>>> "Enable the memmap on memory feature even if it could result in memory waste due to memmap size limitations. For example, if the memmap for a memory block requires 1 MiB, but the pageblock size is 2 MiB, 1 MiB >>>> of hotplugged memory will be wasted. Note that there are still cases where the feature cannot be enforced: for example, if the memmap is smaller than a single page, or if the architecture does not support the forced mode in all configurations." >>>> >>>> Thoughts? >>>> >>> >>> With module parameter, do we still need the Kconfig option? >> >> No. >> >> Sleeping over this, maybe we can convert the existing >> memory_hotplug.memmap_on_memory parameter to also accept "force". >> > > How about this? > > modified mm/memory_hotplug.c > @@ -45,13 +45,67 @@ > /* > * memory_hotplug.memmap_on_memory parameter > */ > -static bool memmap_on_memory __ro_after_init; > -module_param(memmap_on_memory, bool, 0444); > -MODULE_PARM_DESC(memmap_on_memory, "Enable memmap on memory for memory hotplug"); > +enum { > + MEMMAP_ON_MEMORY_DISABLE = 0, > + MEMMAP_ON_MEMORY_ENABLE, > + FORCE_MEMMAP_ON_MEMORY, MEMMAP_ON_MEMORY_FORCE ? > +}; > +static int memmap_mode __read_mostly = MEMMAP_ON_MEMORY_DISABLE; > +static const char *memmap_on_memory_to_str[] = { > + [MEMMAP_ON_MEMORY_DISABLE] = "disable", > + [MEMMAP_ON_MEMORY_ENABLE] = "enable", > + [FORCE_MEMMAP_ON_MEMORY] = "force", > +}; > + > +static inline unsigned long memory_block_align_base(unsigned long size) > +{ > + if (memmap_mode == FORCE_MEMMAP_ON_MEMORY) { > + unsigned long align; > + unsigned long nr_vmemmap_pages = size >> PAGE_SHIFT; > + unsigned long vmemmap_size; > + > + vmemmap_size = DIV_ROUND_UP(nr_vmemmap_pages * sizeof(struct page), PAGE_SIZE); > + align = pageblock_align(vmemmap_size) - vmemmap_size; > + return align; > + } else > + return 0; ^ have to see that in action :) > +} > + > +static int set_memmap_mode(const char *val, const struct kernel_param *kp) > +{ > + int ret = sysfs_match_string(memmap_on_memory_to_str, val); > + That would break existing cmdlines that eat Y/N/0/..., no? Maybe try parsing "force/FORCE" first and then fallback to the common bool parsing (kstrtobool). Same when printing: handle "force" separately and then just print Y/N like param_get_bool() used to do. So you'd end up with Y/N/FORCE as output and Y/N/0/.../FORCE/force as input. But I'm happy to hear about alternatives. Maybe a second parameter is better ... but what name should it have "memmap_on_memory_force" sounds wrong. We'd need a name that expresses that we might be wasting memory, hm ... > + if (ret < 0) > + return ret; > + *((int *)kp->arg) = ret; > + if (ret == FORCE_MEMMAP_ON_MEMORY) { > + pr_info("Memory hotplug will reserve %ld pages in each memory block\n", > + memory_block_align_base(memory_block_size_bytes())); > + } > + return 0; > +} > + > +static int get_memmap_mode(char *buffer, const struct kernel_param *kp) > +{ > + return sprintf(buffer, "%s\n", memmap_on_memory_to_str[*((int *)kp->arg)]); > +} > + > +static const struct kernel_param_ops memmap_mode_ops = { > + .set = set_memmap_mode, > + .get = get_memmap_mode, > +}; > +module_param_cb(memmap_on_memory, &memmap_mode_ops, &memmap_mode, 0644); > +MODULE_PARM_DESC(memmap_on_memory, "Enable memmap on memory for memory hotplug\n" > + "With value \"force\" it could result in memory waste due to memmap size limitations \n" > + "For example, if the memmap for a memory block requires 1 MiB, but the pageblock \n" > + "size is 2 MiB, 1 MiB of hotplugged memory will be wasted. Note that there are \n" > + "still cases where the feature cannot be enforced: for example, if the memmap is \n" > + "smaller than a single page, or if the architecture does not support the forced \n" > + "mode in all configurations. (disable/enable/force)"); > > static inline bool mhp_memmap_on_memory(void) > { > - return memmap_on_memory; > + return !!memmap_mode; > } > #else > > We can also enable runtime enable/disable/force the feature. We just > need to make sure on try_remove_memory we lookup for altmap correctly. > Yes, that's already been asked for. But let's do that as a separate change later. -- Cheers, David / dhildenb