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 ABDB4C6FD1F for ; Thu, 21 Mar 2024 18:50:06 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 3D6786B0089; Thu, 21 Mar 2024 14:50:06 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 385D46B008C; Thu, 21 Mar 2024 14:50:06 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 227736B0093; Thu, 21 Mar 2024 14:50:06 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id 0E6116B0089 for ; Thu, 21 Mar 2024 14:50:06 -0400 (EDT) Received: from smtpin08.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id D728DA20CB for ; Thu, 21 Mar 2024 18:50:05 +0000 (UTC) X-FDA: 81921935970.08.FA4B45C Received: from mail-yb1-f202.google.com (mail-yb1-f202.google.com [209.85.219.202]) by imf11.hostedemail.com (Postfix) with ESMTP id EC31E40014 for ; Thu, 21 Mar 2024 18:50:03 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=muB3QUwc; spf=pass (imf11.hostedemail.com: domain of 3W4H8ZQoKCIY8y218krwonqyyqvo.mywvsx47-wwu5kmu.y1q@flex--yosryahmed.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3W4H8ZQoKCIY8y218krwonqyyqvo.mywvsx47-wwu5kmu.y1q@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1711047004; 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=yxgy+XSydVj6yCHwL0RWD8kNJVN9srA11aLpjbAkYss=; b=UbVnig2ik8cuWyhQXCOwLoEfsMG6MN50EL7Z5t5PBxNfvicJFlDEgFJuP9QmP0wZLWzbyH WjFx59YnHFPK1C+fXViF+T1GXKHg7An6CVIXGMm3K20Nrkj1hxtkOKRHF8bf5CewbZ/xkB 5sMuR03JFNvcks+0aSkUzahUuaD7eB0= ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1711047004; a=rsa-sha256; cv=none; b=r5E5JEZpVu/58eReg/SHx4+HUKD4MPYFySLMDIcLElhVkuR8aQqVBheCDfPTCZMT5vY5hz a7sfxW52B1RQuFsoxId2cih9533ZjzbSU/pCblQRq/kVd4/YjbtHCXabUcFkP/Wz3hAYBn xRY9keE0WqYqdMKp0mE5ioM1CoAyDBA= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=pass header.d=google.com header.s=20230601 header.b=muB3QUwc; spf=pass (imf11.hostedemail.com: domain of 3W4H8ZQoKCIY8y218krwonqyyqvo.mywvsx47-wwu5kmu.y1q@flex--yosryahmed.bounces.google.com designates 209.85.219.202 as permitted sender) smtp.mailfrom=3W4H8ZQoKCIY8y218krwonqyyqvo.mywvsx47-wwu5kmu.y1q@flex--yosryahmed.bounces.google.com; dmarc=pass (policy=reject) header.from=google.com Received: by mail-yb1-f202.google.com with SMTP id 3f1490d57ef6-dcbee93a3e1so2109960276.3 for ; Thu, 21 Mar 2024 11:50:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1711047003; x=1711651803; darn=kvack.org; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:from:to:cc:subject:date:message-id :reply-to; bh=yxgy+XSydVj6yCHwL0RWD8kNJVN9srA11aLpjbAkYss=; b=muB3QUwcu+DD3SMrofi9spM8AySsDKUuWeqslgSgpy3xzO9l6ohj4cxy1ZAJXgD02A 0KHreYpTyV8uw0dZpHYEEJGttkWl94VA++Zbyp4yQ44WeogPO0PQ8J5mQSG5LZprV15N CFPDjf3/KO3HP0uJU5HS5WiO/UYnHhWb03+lDdbETdLOzgSpoG+/XHbtJhz4kB745fJr 3cXMq3KezJahkAREScYQxMaXzy0VyD8dsjuq12NCYnzmihdOwaRhnHF7odPGQ+WFzqBz NsaaOC3HXXSIBjsUjD3i7k9crj4uGm1CJuTX/kKmJyiaG2vJuMPwzIdUmv/V/iJwLyk8 AKfQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1711047003; x=1711651803; h=content-transfer-encoding:cc:to:from:subject:message-id:references :mime-version:in-reply-to:date:x-gm-message-state:from:to:cc:subject :date:message-id:reply-to; bh=yxgy+XSydVj6yCHwL0RWD8kNJVN9srA11aLpjbAkYss=; b=ReEVIQVF/IIDErCanqn3zbSYosN+2huXfWos96hgcQt5FR+u4gzdmv3igC6T4q54yz 8mmW07K0YU+UmC46XnyxZfelInE6us5Yz2bfPRSlk9dvFhTIAvHhIA6UJHtZtaVb3gla zXY33lVauX5rsBG9mAWSHCigbki24lHO4nidIlczYfwSkSPx1gFqXmXSawRthzp6KLrq wNgg3vKcqwP/RDFmP5m12INGTY1f6GwqxuH/AAl04NpOenXkqTbf09Xur3FvLBbBvUQx mbbdFuS1OwEPCJIKBrO3AmQ57z+WilYIH1fBUar9YkyQZ6FK3tKaoiEFZujios2pDUuy kfKA== X-Forwarded-Encrypted: i=1; AJvYcCUaKBnwPBBKqcXIe4Yw2C4bx6BKzGEP1jtmxCH8GsF5sGbRNQkQqWsffaFvdIzdE5/kh/dL6b76uDHVDFFKNWH1Cyw= X-Gm-Message-State: AOJu0Yw7uLpno6bsL8ko5eZ4gkzYIU1Fzu9d6fDxJBoWXDhZKLf1VhQM fZpjMaP//79lxxzYsssDoy4XUyd0UN5CSPVgXlCMNG0BCS20Vrh2LWSUqq4dXTy3FI6XH+eR3CF IpnRMGsMYobRtlkhdfw== X-Google-Smtp-Source: AGHT+IHNt/WVaoaUdH0GL6k62EXvpt0JYXxByljjKBWUvQN54u4ZH9zJEUBVgXMJingKPaUYE7DzUSQKAEImKY49 X-Received: from yosry.c.googlers.com ([fda3:e722:ac3:cc00:20:ed76:c0a8:29b4]) (user=yosryahmed job=sendgmr) by 2002:a05:6902:2185:b0:dc8:27e6:cde1 with SMTP id dl5-20020a056902218500b00dc827e6cde1mr1116ybb.5.1711047003090; Thu, 21 Mar 2024 11:50:03 -0700 (PDT) Date: Thu, 21 Mar 2024 18:50:01 +0000 In-Reply-To: Mime-Version: 1.0 References: Message-ID: Subject: Re: [RFC] Storing same-filled pages without a zswap_entry From: Yosry Ahmed To: Chris Li Cc: Johannes Weiner , Nhat Pham , Chengming Zhou , Linux-MM Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable X-Stat-Signature: 5wsed7xgdxh699q4k63wftcxdmxs5eib X-Rspamd-Server: rspam10 X-Rspamd-Queue-Id: EC31E40014 X-Rspam-User: X-HE-Tag: 1711047003-175486 X-HE-Meta: U2FsdGVkX1/m7vfju4q4/tkChtx5RNbid6NT4pogfeIyT9sYWL0I75CgwrFNvvXRDzp+FDMCjvk4sKUXlsMlk+Ojis/JUNu37T8uY+zrJe4vRA3WK1NgzzmCTmBlxlUWVeDJyzxQ0F/LzIs078CJy6hIammLtzx1slkp2aYe2ndzrov9P5M/uU3rgcWzBSZYs+8GJhenV2IuYA/eB2x2HxQFwxEBlTLOes+LGnPdviEa88nS98jFzdEIYE2ApDJ5D8XxMkf1+h+xyqKJbrZZtAWwZrgE6pPRY81zYbL79wVmy5+QBkmuBjt4ABa0VO+tDecwjkJmQQwIXtBM00kDvRBmoT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KwnoFFdadT6VChqdK3nw+FW1Exd7SWsa/8W7tXQ34NGx6vD78in5/VAHNMxTU3atG5IRbc/EP4tDK8xqYMuO+jQWQhRN0IchBdmjLFvmILEwVZRrXdZveB1MpMhPwDPN80HIKxpmxBIhOflfyqhPLBE2sNIJW1GV9n9CiZYufgQY4RE0qsxWtPaWhMs3H5HN4tM3SaLfPP1ye7JF2wyWS1tPvLDpSJaP+jzXikW3Vc= X-Bogosity: Ham, tests=bogofilter, spamicity=0.058307, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: List-Subscribe: List-Unsubscribe: On Wed, Mar 20, 2024 at 09:26:43PM -0700, Chris Li wrote: > On Wed, Mar 20, 2024 at 1:49=E2=80=AFPM Yosry Ahmed wrote: > > > > Hey folks, > > > > I was looking at cleaning up the same-filled handling code in zswap, > > when it hit me that after the xarray conversion, the only member of > > struct zwap_entry that is relevant to same-filled pages is now the > > objcg pointer. > > > > The xarray allows a pointer to be tagged by up to two tags (1 and 3), > > so we can completely avoid allocating a zswap_entry for same-filled > > pages by storing a tagged objcg pointer directly in the xarray > > instead. > > > > Basically the xarray would then either have a pointer to struct > > zswap_entry or struct obj_cgroup, where the latter is tagged as > > SAME_FILLED_ONE or SAME_FILLED_ZERO. > > > > There are two benefits of this: > > - Saving some memory (precisely 64 bytes per same-filled entry). > > - Further separating handling of same-filled pages from compressed > > pages, which results in some nice cleanups (especially in > > zswap_store()). It also makes further improvements easier (e.g. > > skipping limit checking for same-filled entries). > > > > The disadvantage is obviously the complexity needed to handle two > > different types of pointers in the xarray, although I think with the > > correct abstractions this is not a big deal. >=20 > Another idea is we can make the zero fill zswap entry immutable and > share by different pages. That way it does not depend on the xarray > pointer tagging. It can share the same code path with existing zero > fill page handling. Just don't free the zero fill entry. The only relevant item in zswap_entry for same-filled pages is objcg. That cannot be shared by different pages anyway. So basically the immutable zswap entry will just be a magic value that encodes all zero-filled pages. If we are all fine with only supporting zero-filled pages, then I don't see why we should not just store the objcg in the xarray and tag it as such. In fact, we only need to use one of the two available tags in this case. >=20 > I want to reserve the zswap xarray tagging for another purpose. Did you have another purpose in mind? or just for future expansion? As I mentioned above, if we only support zero-filled pages, we only need one of the two available tags. Also, this is an in-kernel change so I think we could always take it back if we really need the tags in the future. >=20 > Just some food for thought. Might have less complexity because it > doesn't need to deal with two different kinds of pointers. I think the complexity is not that much with the right abstractions, but this is best discussed with actual code imo. >=20 > Chris >=20