Apple's open-source XNU kernel on Android phones: its own loader and drivers, Metal on the Adreno. Runs from RAM; a reboot gives the phone back to Android.
C
APFS: keep a vnode's inode record too, and what the measurements actually say
vcvkkbacfb5b85ccc
diff --git a/xnu/files/bsd/miscfs/apfs/apfs.h b/xnu/files/bsd/miscfs/apfs/apfs.hindex ac76c3d..43f7420 100644--- a/xnu/files/bsd/miscfs/apfs/apfs.h+++ b/xnu/files/bsd/miscfs/apfs/apfs.h@@ -57,6 +57,13 @@ struct apfs_node {* Guarded by am_lock, like everything else that reaches apfs_lib.*/struct apfs_cfile an_cf;+ /*+ * The inode record as it was when the vnode was made. Nothing on this volume can+ * change -- the mount is read only and there is no writer anywhere -- so there is+ * nothing to invalidate, and a read no longer walks the tree for the record and the+ * decmpfs header on every call.+ */+ struct apfs_inode an_ino;};#define APFS_MP(mp) ((struct apfs_mount *)vfs_fsprivate(mp))diff --git a/xnu/files/bsd/miscfs/apfs/apfs_vfsops.c b/xnu/files/bsd/miscfs/apfs/apfs_vfsops.cindex 50879aa..1975c12 100644--- a/xnu/files/bsd/miscfs/apfs/apfs_vfsops.c+++ b/xnu/files/bsd/miscfs/apfs/apfs_vfsops.c@@ -144,6 +144,7 @@ apfs_node_vnode(struct apfs_mount *am, uint64_t obj_id, vnode_t dvp,an->an_parent = ino.parent_id;an->an_mode = ino.mode;an->an_size = size;+ an->an_ino = ino; /* nothing here can change: the mount is read only */bzero(&vfsp, sizeof(vfsp));vfsp.vnfs_mp = am->am_mp;diff --git a/xnu/files/bsd/miscfs/apfs/apfs_vnops.c b/xnu/files/bsd/miscfs/apfs/apfs_vnops.cindex 23e6fba..710db07 100644--- a/xnu/files/bsd/miscfs/apfs/apfs_vnops.c+++ b/xnu/files/bsd/miscfs/apfs/apfs_vnops.c@@ -101,20 +101,8 @@ apfs_vnop_getattr(struct vnop_getattr_args *ap)uint64_t size = 0;int error;- apfs_lock(am);- error = apfs_vp_inode(vp, &ino);- if (error == 0) {- error = apfs_inode_size(&am->am_vol, &ino, &size);- if (error) {- size = ino.size;- error = 0;- }- }- apfs_unlock(am);- if (error) {- return error;- }- an->an_size = size;+ ino = an->an_ino;+ size = an->an_size;VATTR_RETURN(vap, va_rdev, (dev_t)ino.rdev);VATTR_RETURN(vap, va_nlink, vnode_isdir(vp) ? 2 : (uint32_t)(ino.nchildren > 0@@ -171,7 +159,7 @@ apfs_vnop_read(struct vnop_read_args *ap)struct apfs_inode ino;uint8_t *buf;uint64_t size = 0;- int error;+ int error = 0;if (vnode_isdir(vp)) {return EISDIR;@@ -182,15 +170,8 @@ apfs_vnop_read(struct vnop_read_args *ap)if (uio_offset(uio) < 0) {return EINVAL;}- apfs_lock(am);- error = apfs_vp_inode(vp, &ino);- if (error == 0) {- error = apfs_inode_size(&am->am_vol, &ino, &size);- }- apfs_unlock(am);- if (error) {- return error;- }+ ino = APFS_VP(vp)->an_ino;+ size = APFS_VP(vp)->an_size;buf = kalloc_data(APFS_IOBUF, Z_WAITOK);if (buf == NULL) {return ENOMEM;@@ -244,13 +225,9 @@ apfs_vnop_pagein(struct vnop_pagein_args *ap)(upl_offset & PAGE_MASK)) {error = EINVAL;} else {- apfs_lock(am);- error = apfs_vp_inode(vp, &ino);- if (error == 0) {- error = apfs_inode_size(&am->am_vol, &ino, &size);- }- apfs_unlock(am);- if (error == 0 && ubc_upl_map(upl, &address) != KERN_SUCCESS) {+ ino = APFS_VP(vp)->an_ino;+ size = APFS_VP(vp)->an_size;+ if (ubc_upl_map(upl, &address) != KERN_SUCCESS) {error = ENOMEM;}}@@ -262,6 +239,20 @@ apfs_vnop_pagein(struct vnop_pagein_args *ap)return error;}+ /*+ * Say once how big a range the paging machinery asks for. It decides how much the+ * holding of a decompressed piece can save: if a request already covers a whole+ * 64 KB piece, the piece was being decompressed once per request anyway.+ */+ {+ static bool said;++ if (!said) {+ said = true;+ printf("apfs: pagein asks for %u bytes at a time (page size %u)\n",+ (unsigned)ap->a_size, (unsigned)PAGE_SIZE);+ }+ }end = offset + (off_t)ap->a_size;for (at = offset; at < end;) {uint8_t *dst = (uint8_t *)address + upl_offset + (at - offset);