Received: by 2002:ab2:69cc:0:b0:1f4:be93:e15a with SMTP id n12csp267379lqp; Fri, 12 Apr 2024 18:06:27 -0700 (PDT) X-Forwarded-Encrypted: i=3; AJvYcCWWqZv53B0f+bajtcbKZJeC9RLTDB59f+7l9qrMNbbV9IKLS9CJca+0wUb22zYoR+1cAr+JLpwl+2F2oSbZ+q8Q8MdgaaqxT8Op80YCug== X-Google-Smtp-Source: AGHT+IG4wobHgi5g6CdeD5KxpwpvQcQc3jLixXplLn38hYAU4wfVzgGiebmylmV3RAYhTV3sJSxn X-Received: by 2002:a05:6a00:806:b0:6ec:ebf4:3e8a with SMTP id m6-20020a056a00080600b006ecebf43e8amr5565425pfk.15.1712970386768; Fri, 12 Apr 2024 18:06:26 -0700 (PDT) ARC-Seal: i=2; a=rsa-sha256; t=1712970386; cv=pass; d=google.com; s=arc-20160816; b=n7k3NMpBDmM4PCuUGE2L0Vm4OjysAN32/M0jUtslYCe4chLxJe0wlhTyptmchkjSJI cjpvZ8CHCAc3ZU6b7wLZkkTbYd3VGdnW4EuRqJI7g7d1lvl7S58wCw5IawEBfYCEniEz 0o4qzb2Zu7QN4DVvGropSsMHFpfiBP9dM0KQrXPqZkw/Xz7NqzvT85kR8DTFcqyCpfc7 n4ZIr4xr0VxCmV+Q0VFm1IqqxH5zk4lWkE3ks1f2ZfkT8JLmYqBukFfYzfw3Qkwaae0x szjVuD3x2x2XuFRwmmX7dQSZwx7rFm/CLfRYhjvM4o4op8w9ZxhNAk49KRETshonsCJD 7tEw== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:list-unsubscribe:list-subscribe :list-id:precedence:dkim-signature; bh=MHmucI/H5NxibwlUQ0js8/JOPLCBsTS2p7VG0CvPNNo=; fh=Cm4+8o8VbU9DuuPeFd8YyRlA8gl5bb9Sk1RzlDqhvYs=; b=KJAciJEI61vd8QONXrkLonoSeQ6wc3r3IRIXel4Zv5wpxoXx8Ze2O8nM231t6soLxs mXQ4qG5xtDm0IhVwLcjuBham2K6FGHM5tXYtwbtZ6OJN2vYuVujplxy+ZM3rFHhRCBW4 wi4dmviUVXgzFV/NlNrM5AYuEgM5X2dJ2NCg8egw+SthIoTuGvhvEgdYMPsVSw/Z89xW UEOzUDT7/W1Y2AXl1xgU5EiTzU7uelTb1If0W+YwD3H25sI6V2HXRPaf8cIM6qrdnpLm bmVkARzUufr8zOEmnycdgrLaavk+y7AMqnIqTMFMpRCOTnJN+Sg9vmRBAqChxshhvjSC VT1w==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=m9kDvazX; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-143486-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143486-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [2604:1380:45e3:2400::1]) by mx.google.com with ESMTPS id s10-20020a056a00178a00b006eced1a16absi4394005pfg.200.2024.04.12.18.06.26 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 12 Apr 2024 18:06:26 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel+bounces-143486-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) client-ip=2604:1380:45e3:2400::1; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20230601 header.b=m9kDvazX; arc=pass (i=1 spf=pass spfdomain=google.com dkim=pass dkdomain=google.com dmarc=pass fromdomain=google.com); spf=pass (google.com: domain of linux-kernel+bounces-143486-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:45e3:2400::1 as permitted sender) smtp.mailfrom="linux-kernel+bounces-143486-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 66E89282D3B for ; Sat, 13 Apr 2024 01:06:26 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 857D66AB8; Sat, 13 Apr 2024 01:06:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="m9kDvazX" Received: from mail-lf1-f54.google.com (mail-lf1-f54.google.com [209.85.167.54]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EB2484C65 for ; Sat, 13 Apr 2024 01:06:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.167.54 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712970379; cv=none; b=TjBPAHcBosSzFWInLTN5d2rW6LX4tvk1Zn34yTm7EBNGm7HyzHaYIGCYHCBg1w0L8RWxjoGMbJB1n0zAOYw9ytriIl6H4IOd1GIqL7PEKpZILUYfBDCTqS/pdMtFqwIk/kTOYAEePE3BVd9BlZ1LWgzW/76rd+lGdvYGd2vENOA= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1712970379; c=relaxed/simple; bh=MHmucI/H5NxibwlUQ0js8/JOPLCBsTS2p7VG0CvPNNo=; h=MIME-Version:References:In-Reply-To:From:Date:Message-ID:Subject: To:Cc:Content-Type; b=Z4hWFbdbLqgP9qogw8Mca3IcW0wyAXwe3zjkLB8LOnCQA0+C0+Hn3evC/V0fgdGlwpr0pzvqJcaOTeFj2HcET4oiULoMdaEDIxU/yTeX13m2m/WzpTr/xcW/1wUwFovd+IQ/hh5ERqcrTlFSzTv5fK9RKvCyTXvYYRa0eyNslIc= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=m9kDvazX; arc=none smtp.client-ip=209.85.167.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=google.com Received: by mail-lf1-f54.google.com with SMTP id 2adb3069b0e04-516d1ecaf25so1810721e87.2 for ; Fri, 12 Apr 2024 18:06:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1712970376; x=1713575176; darn=vger.kernel.org; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:from:to:cc:subject:date :message-id:reply-to; bh=MHmucI/H5NxibwlUQ0js8/JOPLCBsTS2p7VG0CvPNNo=; b=m9kDvazXq5P6Z2jCFUucDb31pK8mSAtfCN4bGMt28LuW4H9B9idjxoe97NybOkEkiC F1FdhncIf3UN8mmWichl7VqWx/tf3b1ySZ6Y7SBY+MZCtzGZOkH+t6pJjjOWCCLdYgs1 xD7ucjGSRde9Cr/IKLxeeYXk8k7/q/Wh2ML70+UY6Ae7h9f/ADlv8GetuDH8g05tuQN5 qhQpEpilbnHCaNWiiKajcd3P0YSJQYQrop74svBt2ucUnTpQelms91jeZrGOKuDfBM1h L/uLmqMVgKt9e9gU58c4LnNL7DPbeI9eJ+ThfeLvImN2tA+MlfjoTLg2YVAJVp/p1Zhi rtsw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1712970376; x=1713575176; h=content-transfer-encoding:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=MHmucI/H5NxibwlUQ0js8/JOPLCBsTS2p7VG0CvPNNo=; b=vtdsEvozdpncwOuMw7ddRUCE/65GzEbhw4s2Ysb8m8Ob6iUpLtAmsQ28d7lnSONAeq I1ljXDxqFxmgNBUUocXhoMBXOCserClhe1Sk69yWbO8YJ5JLXabNJUBNHUwDYS8Tmzrw rdm7XzZ4ta37taDbbpxxcA5ZMDfODZa26rQaX4MdS/UUPtDmGqN7JoL4p3E2YbO4BSyK mzNXhbrPBVrrJkhfPZ5zvJ44uKilAx8EdSxUvivI9WhuGsoliu0FHn4xyDoanYRQL8nj zeYeCjR5Kb81G8V3blW28713Sb+cmpftYO6MMTz3+DpDqxBNMEuo7Ga+a+tGQW0rdWt8 GTGw== X-Forwarded-Encrypted: i=1; AJvYcCUk8QxaFeSZAPvRMyux5AUVRHi3IMNlxJwpzuMF3yVSuV8nXd1E/1FPippiOqNR2zpuWAezqi9raYoWEuGHaHMq7JTCobepfs8HCvr/ X-Gm-Message-State: AOJu0YyedpmGzOZ4KFFcR0K9u8dWfmZi9JuqtjBJai/T738gJhEdcKKc h/4DAh1HweSsI/abtLmXfmlX/NxLyzmm7ZeZQe8bi/gKuYOkp44xMxv/0E31Y7tw8+vyjvFjXYX bEcoK0VtL4pu20XcSt/jnNjyzVVdAHC3eQYlXvHxwpad1b8nU3FcYeP8= X-Received: by 2002:ac2:430d:0:b0:513:5951:61a4 with SMTP id l13-20020ac2430d000000b00513595161a4mr2495959lfh.6.1712970375757; Fri, 12 Apr 2024 18:06:15 -0700 (PDT) Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 References: <20240405053510.1948982-1-yosryahmed@google.com> <20240405053510.1948982-3-yosryahmed@google.com> <20240405152619.GA866431@cmpxchg.org> <7aec7b98-db81-4238-bdd6-afb69679f852@redhat.com> <69dcd33b-e8de-4927-93dd-d4ea22834a18@redhat.com> In-Reply-To: From: Yosry Ahmed Date: Fri, 12 Apr 2024 18:05:39 -0700 Message-ID: Subject: Re: [PATCH v2 2/5] mm: zswap: calculate limits only when updated To: David Hildenbrand Cc: Johannes Weiner , Andrew Morton , Nhat Pham , Chengming Zhou , linux-mm@kvack.org, linux-kernel@vger.kernel.org Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable On Fri, Apr 12, 2024 at 12:48=E2=80=AFPM David Hildenbrand wrote: > > On 10.04.24 02:52, Yosry Ahmed wrote: > > [..] > >>> Do we need a separate notifier chain for totalram_pages() updates? > >> > >> Good question. I actually might have the requirement to notify some ar= ch > >> code (s390x) from virtio-mem when fake adding/removing memory, and > >> already wondered how to best wire that up. > >> > >> Maybe we can squeeze that into the existing notifier chain, but needs = a > >> bit of thought. > > > > Sorry for the late reply, I had to think about this a bit. > > > Do you mean by adding new actions (e.g. MEM_FAKE_ONLINE, > > MEM_FAKE_OFFLINE), or by reusing the existing actions (MEM_ONLINE, > > MEM_OFFLINE, etc). > > At least for virtio-mem, I think we could have a MEM_ONLINE/MEM_OFFLINE > that prepare the whole range belonging to the Linux memory block > (/sys/devices/system/memory/memory...) to go online, and then have > something like MEM_SOFT_ONLINE/MEM_SOFT_OFFLINE or > ENABLE_PAGES/DISABLE_PAGES ... notifications when parts become usable > (!PageOffline, handed to the buddy) or unusable (PageOffline, removed > from the buddy). > > There are some details to be figured out, but it could work. > > And as virtio-mem currently operates in pageblock granularity (e.g., 2 > MiB), but frequently handles multiple contiguous pageblocks within a > Linux memory block, it's not that bad. > > > But the issue I see with ballooning is that we operate here often on > page granularity. While we could optimize some cases, we might get quite > some overhead from all the notifications. Alternatively, we could send a > list of pages, but it won't win a beauty contest. > > I think the main issue is that, for my purpose (virtio-mem on s390x), I > need to notify about the exact memory ranges (so I can reinitialize > stuff in s390x code when memory gets effectively re-enabled). For other > cases (total pages changing), we don't need the memory ranges, but only > the "summary" -- or a notification afterwards that the total pages were > just changed quite a bit. Thanks for shedding some light on this. Although I am not familiar with ballooning, sending notifications on page granularity updates sounds terrible. It seems like this is not as straightforward as I had anticipated. I was going to take a stab at this, but given that the motivation is a minor optimization on the zswap side, I will probably just give up :) For now, I will drop this optimization from the series for now, and I can revisit it if/when notifications for totalram_pages() are implemented at some point. Please CC me if you do so for the s390x use case :) > > > > > > New actions mean minimal impact to existing notifiers, but it may make > > more sense to reuse MEM_ONLINE and MEM_OFFLINE to have generic actions > > that mean "memory increased" and "memory decreased". > > Likely, we should keep their semantics unchanged. Things like KASAN want > to allocate metadata memory for the whole range, not on some smallish > pieces. It really means "This Linux memory block goes online/offline, > please prepare for that.". And again, memory ballooning with small pages > is a bit problematic. > > > > > I suppose we can add new actions and then separately (and probably > > incrementally) audit existing notifiers to check if they want to > > handle the new actions as well. > > > > Another consideration is that apparently some ballooning drivers also > > register notifiers, so we need to make sure there is no possibility of > > deadlock/recursion. > > Right. > > -- > Cheers, > > David / dhildenb >