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: read(2) through the page cache, as decmpfs reads a compressed HFS file
vcvkk22b0de7ce750
diff --git a/userland/rc.jobs.flashcache b/userland/rc.jobs.flashcachenew file mode 100644index 0000000..2d1d339--- /dev/null+++ b/userland/rc.jobs.flashcache@@ -0,0 +1,32 @@+# Commands run by the launchd job com.redwood.demo (see com.redwood.demo.plist).+# The iOS root volume on the phone's flash as the root (flashboot.packfs resident, root_apfs=ufs_darwin+# ufs=2 ufs_native=1), read(2) through the page cache. The driver's numbers and the kernel's line about+# memory for the boot (until 25 s after this list began: nothing of ours meanwhile) and the next 30 s;+# then /usr/sbin and /usr/libexec, each: out of the page cache (drop), read(2) cold and warm, a mapping+# over what read(2) put there, out again, a mapping cold and warm, read(2) over what the mapping put+# there -- every pass with its sum (3095b9e298a4df17, 978ed0d4dda1a256), only the totals printed.+# The results go to a file and are shown at the end, where the kernel's log keeps them.+sleep 25+/redwood/bin/vol_ls sysctl kern.apfs_stats kern.redwood_memory >> /private/var/results+/redwood/bin/vol_ls zero kern.apfs_stats+sleep 30+/redwood/bin/vol_ls sysctl kern.apfs_stats kern.redwood_memory >> /private/var/results+/redwood/bin/apfs_mmap_test -q drop /usr/sbin >> /private/var/results+/redwood/bin/apfs_mmap_test -q read /usr/sbin 65536 >> /private/var/results+/redwood/bin/apfs_mmap_test -q read /usr/sbin 65536 >> /private/var/results+/redwood/bin/apfs_mmap_test -q mmap /usr/sbin >> /private/var/results+/redwood/bin/apfs_mmap_test -q drop /usr/sbin >> /private/var/results+/redwood/bin/apfs_mmap_test -q mmap /usr/sbin >> /private/var/results+/redwood/bin/apfs_mmap_test -q mmap /usr/sbin >> /private/var/results+/redwood/bin/apfs_mmap_test -q read /usr/sbin 65536 >> /private/var/results+/redwood/bin/apfs_mmap_test -q drop /usr/libexec >> /private/var/results+/redwood/bin/apfs_mmap_test -q read /usr/libexec 65536 >> /private/var/results+/redwood/bin/apfs_mmap_test -q read /usr/libexec 65536 >> /private/var/results+/redwood/bin/apfs_mmap_test -q mmap /usr/libexec >> /private/var/results+/redwood/bin/apfs_mmap_test -q drop /usr/libexec >> /private/var/results+/redwood/bin/apfs_mmap_test -q mmap /usr/libexec >> /private/var/results+/redwood/bin/apfs_mmap_test -q mmap /usr/libexec >> /private/var/results+/redwood/bin/apfs_mmap_test -q read /usr/libexec 65536 >> /private/var/results+/redwood/bin/vol_ls sysctl kern.redwood_memory >> /private/var/results+/bin/ps -A >> /private/var/results+/redwood/bin/vol_ls cat /private/var/results 262144diff --git a/userland/src/apfs_mmap_test.c b/userland/src/apfs_mmap_test.cindex 31b0e6f..f9ba7c7 100644--- a/userland/src/apfs_mmap_test.c+++ b/userland/src/apfs_mmap_test.c@@ -16,7 +16,11 @@** usage: apfs_mmap_test [-q] mmap [PATH]* apfs_mmap_test [-q] read [PATH] [CHUNK]+ * apfs_mmap_test drop [PATH]* -q: no line for each file, only the files' count, bytes, line-hash sum and time.+ * drop: each file's pages are put out of the page cache (a shared mapping of it, msync with+ * MS_INVALIDATE), so that the next pass over PATH reads it from the volume again: a cold pass+ * without a reboot. Nothing is hashed, and the driver's counters are left alone.* PATH defaults to /private/var/apfs-check/usr, CHUNK to 4096. PATH may be anywhere on a* mounted volume: the lines name files from that volume's mount point (statfs), which is* what makes them the host's lines.@@ -47,6 +51,7 @@ static const char *tag; /* what to print each line under */static int chunk_size = 4096;static int use_mmap;static int quiet; /* -q: no line a file, only what they add up to */+static int drop_mode; /* drop: out of the page cache, nothing read */static unsigned long long total_sum;static unsigned long long total_bytes;@@ -96,6 +101,14 @@ stats_print(void)if (next != NULL) {*next++ = '\0';}+ /* -q: the totals only (the per-caller and per-process tables are for vol_ls sysctl) */+ if (quiet && strncmp(line, "pagein ", 7) != 0 && strncmp(line, "read ", 5) != 0 &&+ strncmp(line, "device ", 7) != 0 && strncmp(line, "data ", 5) != 0 &&+ strncmp(line, "inflate ", 8) != 0 && strncmp(line, "blocks ", 7) != 0 &&+ !(strncmp(line, "lock ", 5) == 0 && strstr(line, " takes ") != NULL &&+ strstr(line, "metadata") != NULL)) {+ continue;+ }if (*line != '\0') {printf("%s kernel: %s\n", tag, line);}@@ -167,12 +180,49 @@ hash_read(const char *path, off_t size, unsigned long long *out)return 0;}+/* One file's pages out of the page cache: they are the same ones every mapping of it shares. */+static int+drop_file(const char *path, off_t size)+{+ int fd = open(path, O_RDONLY);+ void *map;+ int rc;++ if (fd < 0) {+ return -1;+ }+ if (size == 0) {+ close(fd);+ return 0;+ }+ map = mmap(NULL, (size_t)size, PROT_READ, MAP_SHARED, fd, 0);+ close(fd);+ if (map == MAP_FAILED) {+ return -1;+ }+ rc = msync(map, (size_t)size, MS_INVALIDATE);+ munmap(map, (size_t)size);+ return rc;+}+static voiddo_file(const char *path, off_t size){unsigned long long h = 0;char line[2048];- int rc = use_mmap ? hash_mapped(path, size, &h) : hash_read(path, size, &h);+ int rc;++ if (drop_mode) {+ if (drop_file(path, size) != 0) {+ printf("%s %s: cannot drop it: %s\n", tag, path + mount_len, strerror(errno));+ total_errors++;+ return;+ }+ total_files++;+ total_bytes += (unsigned long long)size;+ return;+ }+ rc = use_mmap ? hash_mapped(path, size, &h) : hash_read(path, size, &h);if (rc != 0) {printf("%s %s: cannot read it: %s\n", tag, path + mount_len,@@ -246,8 +296,9 @@ main(int argc, char **argv)}mode = argc > 1 ? argv[1] : "mmap";+ drop_mode = (strcmp(mode, "drop") == 0);use_mmap = (strcmp(mode, "read") != 0);- tag = use_mmap ? "apfs-mmap:" : "apfs-read:";+ tag = drop_mode ? "apfs-drop:" : use_mmap ? "apfs-mmap:" : "apfs-read:";if (argc > 2) {where = argv[2];}@@ -277,6 +328,15 @@ main(int argc, char **argv)}}+ if (drop_mode) {+ snprintf(path, sizeof(path), "%s", where);+ t0 = now_ms();+ walk(path, strlen(path));+ t1 = now_ms();+ printf("%s %s: files %ld bytes %llu errors %ld, out of the page cache in %.0f ms\n", tag, where,+ total_files, total_bytes, total_errors, t1 - t0);+ return total_errors ? 1 : 0;+ }printf("%s %s, %s%s\n", tag, where, use_mmap ? "through a mapping" : "with read(2)",use_mmap ? "" : " in pieces");if (!use_mmap) {diff --git a/xnu/files/bsd/miscfs/apfs/apfs.h b/xnu/files/bsd/miscfs/apfs/apfs.hindex 435b9d5..c43ca64 100644--- a/xnu/files/bsd/miscfs/apfs/apfs.h+++ b/xnu/files/bsd/miscfs/apfs/apfs.h@@ -73,6 +73,8 @@ struct apfs_mount {* counters (waiting for the device, decompressing). Ticks; see apfs_ticks().*/uint64_t am_pagein_calls, am_pagein_ticks, am_pagein_bytes;+ /* read(2) through the page cache: bytes copied from pages already there, bytes read into it (atomic) */+ uint64_t am_read_cached, am_read_filled;uint64_t am_read_calls, am_read_ticks, am_read_bytes;/** What the one lock round apfs_lib costs: how long callers stood waiting for it, and@@ -140,6 +142,8 @@ struct apfs_mount {uint64_t read_ticks, pagein_ticks; /* time in them, added without the lock (atomic) */} *am_procs;uint32_t am_nprocs;+ lck_spin_t am_procs_spin; /* finding or adding an entry (a read from the page cache has no am_lock) */+ bool am_ubc_read; /* read(2) through the page cache (boot-arg apfs_ubc_read, default 1) */uint32_t am_nops;uint32_t am_untracked; /* operations the table had no room for: nothing is freed meanwhile *//* how long it was held: up to 10 us, 100 us, 1 ms, 10 ms, more; and the longest */@@ -195,6 +199,9 @@ struct apfs_node {* Put in once (atomically), read without the lock, freed with the vnode.*/struct apfs_link *an_link;+ /* read(2) through the page cache: where a reader in order would read next, and how much it was given ahead (hints, atomic) */+ uint64_t an_read_next;+ uint32_t an_read_window;};struct apfs_link {diff --git a/xnu/files/bsd/miscfs/apfs/apfs_vfsops.c b/xnu/files/bsd/miscfs/apfs/apfs_vfsops.cindex 6a01808..1fef917 100644--- a/xnu/files/bsd/miscfs/apfs/apfs_vfsops.c+++ b/xnu/files/bsd/miscfs/apfs/apfs_vfsops.c@@ -249,7 +249,7 @@ sysctl_apfs_stats SYSCTL_HANDLER_ARGSsnprintf(text, cap,"pagein %llu calls %llu ms %llu bytes\n"- "read %llu calls %llu ms %llu bytes\n"+ "read %llu calls %llu ms %llu bytes; from the page cache %llu, read into it %llu (%s)\n""device %llu calls %llu ms %llu bytes\n""data %llu calls %llu ms %llu bytes\n""inflate %llu calls %llu ms %llu bytes in %llu bytes out %llu by zlib\n"@@ -262,6 +262,9 @@ sysctl_apfs_stats SYSCTL_HANDLER_ARGS(unsigned long long)am->am_read_calls,(unsigned long long)apfs_ticks_ms(am->am_read_ticks),(unsigned long long)am->am_read_bytes,+ (unsigned long long)am->am_read_cached,+ (unsigned long long)am->am_read_filled,+ am->am_ubc_read ? "read(2) through it" : "read(2) past it: apfs_ubc_read=0",(unsigned long long)nx->dev_calls,(unsigned long long)apfs_ticks_ms(nx->dev_ticks),(unsigned long long)nx->dev_bytes,@@ -314,10 +317,13 @@ sysctl_apfs_stats SYSCTL_HANDLER_ARGSmemset(am->am_long_queued, 0, sizeof(am->am_long_queued));memset(am->am_long_oncpu, 0, sizeof(am->am_long_oncpu));memset(am->am_long_cpu, 0, sizeof(am->am_long_cpu));+ lck_spin_lock(&am->am_procs_spin);if (am->am_procs != NULL) {memset(am->am_procs, 0, APFS_LOCK_PROCS * sizeof(am->am_procs[0]));}am->am_nprocs = 0;+ lck_spin_unlock(&am->am_procs_spin);+ am->am_read_cached = am->am_read_filled = 0;for (uint32_t i = 0; i < APFS_LOCK_SITES; i++) {const char *name = am->am_sites[i].name;@@ -410,6 +416,22 @@ apfs_stats_print(void)}}+/* kern.redwood_memory: the kernel's line about memory (osfmk/arm64/loader_return.c), for a job list to keep */+extern void redwood_memory_line(char *buf, size_t len);++static int+sysctl_redwood_memory SYSCTL_HANDLER_ARGS+{+#pragma unused(oidp, arg1, arg2)+ char line[256];++ redwood_memory_line(line, sizeof(line));+ return SYSCTL_OUT(req, line, strlen(line) + 1);+}++SYSCTL_PROC(_kern, OID_AUTO, redwood_memory, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_LOCKED,+ 0, 0, sysctl_redwood_memory, "A", "where the memory is, in MB");+SYSCTL_PROC(_kern, OID_AUTO, apfs_stats, CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_LOCKED,0, 0, sysctl_apfs_stats, "A", "APFS: where the time goes; write to zero it");@@ -913,6 +935,7 @@ apfs_free_mount(struct apfs_mount *am)kfree_data(am->am_procs, APFS_LOCK_PROCS * sizeof(am->am_procs[0]));}lck_spin_destroy(&am->am_iobuf_spin, &apfs_lck_grp);+ lck_spin_destroy(&am->am_procs_spin, &apfs_lck_grp);lck_mtx_destroy(&am->am_lock, &apfs_lck_grp);kfree_type(struct apfs_mount, am);}@@ -940,6 +963,13 @@ apfs_mount_common(mount_t mp, vnode_t devvp, vfs_context_t ctx)}lck_mtx_init(&am->am_lock, &apfs_lck_grp, LCK_ATTR_NULL);lck_spin_init(&am->am_iobuf_spin, &apfs_lck_grp, LCK_ATTR_NULL);+ lck_spin_init(&am->am_procs_spin, &apfs_lck_grp, LCK_ATTR_NULL);+ {+ uint32_t ubc = 1;++ (void)PE_parse_boot_argn("apfs_ubc_read", &ubc, sizeof(ubc));+ am->am_ubc_read = (ubc != 0);+ }am->am_procs = kalloc_data(APFS_LOCK_PROCS * sizeof(am->am_procs[0]), Z_WAITOK | Z_ZERO);am->am_mp = mp;am->am_devvp = devvp;diff --git a/xnu/files/bsd/miscfs/apfs/apfs_vnops.c b/xnu/files/bsd/miscfs/apfs/apfs_vnops.cindex e9f38d9..de63dd8 100644--- a/xnu/files/bsd/miscfs/apfs/apfs_vnops.c+++ b/xnu/files/bsd/miscfs/apfs/apfs_vnops.c@@ -33,7 +33,8 @@ extern void thread_runnable_and_run_self(uint64_t *runnable, uint64_t *run);static struct apfs_lock_proc *lock_proc(struct apfs_mount *am){- static struct apfs_lock_proc nowhere; /* (no table: counted, under the lock, and never shown) */+ static struct apfs_lock_proc nowhere; /* (no table: counted, and never shown) */+ struct apfs_lock_proc *lp;char name[MAXCOMLEN + 1];uint32_t i;@@ -41,20 +42,26 @@ lock_proc(struct apfs_mount *am)return &nowhere;}proc_selfname(name, sizeof(name));+ lck_spin_lock(&am->am_procs_spin);for (i = 0; i < am->am_nprocs; i++) {if (strncmp(am->am_procs[i].name, name, sizeof(name)) == 0) {- return &am->am_procs[i];+ lp = &am->am_procs[i];+ goto out;}}if (am->am_nprocs < APFS_LOCK_PROCS - 1) {strlcpy(am->am_procs[am->am_nprocs].name, name, sizeof(name));- return &am->am_procs[am->am_nprocs++];+ lp = &am->am_procs[am->am_nprocs++];+ goto out;}if (am->am_nprocs == APFS_LOCK_PROCS - 1) {strlcpy(am->am_procs[am->am_nprocs].name, "(the rest)", sizeof(name));am->am_nprocs++;}- return &am->am_procs[APFS_LOCK_PROCS - 1];+ lp = &am->am_procs[APFS_LOCK_PROCS - 1];+out:+ lck_spin_unlock(&am->am_procs_spin);+ return lp;}/* The statistics of a caller of apfs_lock (with the lock held) */@@ -438,8 +445,160 @@ apfs_iobuf_put(struct apfs_mount *am, uint8_t *buf)}}+/*+ * read(2) through the page cache, as decmpfs reads a compressed HFS file+ * (decmpfs_read_compressed): what the cache has is copied from it; for the rest the file's+ * pages are taken in a UPL, the ones not valid yet read into it by apfs_read_file -- what+ * pagein does -- and the UPL committed, so that the pages stay: the next read(2) of them+ * finds them, and so does a mapping of the file, which is the same pages. At least+ * APFS_FILL_ALIGN at a time, aligned to it: a compressed file is kept in 64 KB pieces, and a+ * piece decompressed for a small read would be decompressed again for the next one.+ */+#define APFS_FILL_ALIGN (64 * 1024)+#define APFS_FILL_MAX (1024 * 1024) /* at most this much in one UPL */+/*+ * A reader going through a file in order (it starts where the last read(2) of the file ended)+ * is given more than it asked for, twice as much each time it comes to the end of what it was+ * given, up to APFS_FILL_MAX: fewer UPLs, larger requests to the device. The cluster layer+ * does the same for a file system that uses it.+ */++/* [at, at + len) of the file into dst, as pagein reads it; past the end, zeros */static int-apfs_vnop_read(struct vnop_read_args *ap)+apfs_fill(struct apfs_mount *am, vnode_t vp, struct apfs_inode *ino, uint64_t size, off_t at,+ uint8_t *dst, size_t len, uint64_t *filled)+{+ int error = 0;++ while (len > 0) {+ size_t want, got = 0;++ if ((uint64_t)at >= size) {+ bzero(dst, len);+ break;+ }+ want = (size_t)MIN((uint64_t)len, size - (uint64_t)at);+ os_atomic_inc(&am->am_nx.requests, relaxed);+ apfs_lock(am);+ error = apfs_read_file(&am->am_vol, ino, &APFS_VP(vp)->an_cf, (uint64_t)at, dst, want, &got);+ apfs_unlock(am);+ os_atomic_dec(&am->am_nx.requests, relaxed);+ if (error) {+ break;+ }+ if (got == 0) {+ bzero(dst, len); /* (shorter than its size says: zeros, as pagein gives) */+ break;+ }+ at += (off_t)got;+ dst += got;+ len -= got;+ *filled += got;+ }+ return error;+}++static int+apfs_read_cached(struct apfs_mount *am, vnode_t vp, struct uio *uio, struct apfs_inode *ino,+ uint64_t size, uint64_t *cached, uint64_t *filled)+{+ int error = 0;++ while (uio_resid(uio) > 0 && (uint64_t)uio_offset(uio) < size) {+ uint64_t left = MIN((uint64_t)uio_resid(uio), size - (uint64_t)uio_offset(uio));+ int count = (int)MIN(left, (uint64_t)INT_MAX), resid = count, copy, copy_resid, npages, i;+ off_t pos, want_end, upl_pos, upl_end;+ upl_page_info_t *pl = NULL;+ vm_offset_t address = 0;+ upl_t upl = NULL;+ int upl_size;++ /* what the cache has already, up to the first page it has not */+ error = cluster_copy_ubc_data(vp, uio, &resid, 0);+ *cached += (uint64_t)(count - resid);+ if (error) {+ break;+ }+ if (resid == 0) {+ continue;+ }++ /* the rest: the pages from there, the missing ones read in */+ pos = uio_offset(uio);+ left = MIN((uint64_t)uio_resid(uio), size - (uint64_t)pos);+ want_end = pos + (off_t)left;+ upl_pos = pos & ~((off_t)APFS_FILL_ALIGN - 1);+ upl_end = (want_end + APFS_FILL_ALIGN - 1) & ~((off_t)APFS_FILL_ALIGN - 1);+ {+ struct apfs_node *an = APFS_VP(vp);+ uint32_t window = APFS_FILL_ALIGN;++ /* (where this read(2) began: before what the cache gave it just now) */+ if ((uint64_t)pos - (uint64_t)(count - resid) == os_atomic_load(&an->an_read_next, relaxed)) {+ window = MIN(MAX(os_atomic_load(&an->an_read_window, relaxed) * 2,+ (uint32_t)APFS_FILL_ALIGN), (uint32_t)APFS_FILL_MAX);+ }+ os_atomic_store(&an->an_read_window, window, relaxed);+ if (upl_end < upl_pos + (off_t)window) {+ upl_end = upl_pos + (off_t)window;+ }+ }+ if (upl_end > (off_t)round_page_64(size)) {+ upl_end = (off_t)round_page_64(size);+ }+ if (upl_end - upl_pos > APFS_FILL_MAX) {+ upl_end = upl_pos + APFS_FILL_MAX;+ }+ upl_size = (int)(upl_end - upl_pos);+ if (ubc_create_upl_kernel(vp, upl_pos, upl_size, &upl, &pl, UPL_SET_LITE,+ VM_KERN_MEMORY_FILE) != KERN_SUCCESS || upl == NULL) {+ error = EIO;+ break;+ }+ if (ubc_upl_map(upl, &address) != KERN_SUCCESS || address == 0) {+ ubc_upl_abort_range(upl, 0, (upl_size_t)upl_size, UPL_ABORT_FREE_ON_EMPTY);+ error = EIO;+ break;+ }+ npages = upl_size / PAGE_SIZE;+ for (i = 0; i < npages && error == 0;) {+ int j;++ if (upl_valid_page(pl, i)) {+ i++;+ continue;+ }+ for (j = i + 1; j < npages && !upl_valid_page(pl, j); j++) {+ }+ error = apfs_fill(am, vp, ino, size, upl_pos + (off_t)i * PAGE_SIZE,+ (uint8_t *)address + (size_t)i * PAGE_SIZE, (size_t)(j - i) * PAGE_SIZE, filled);+ i = j;+ }+ (void)ubc_upl_unmap(upl);+ if (error) {+ ubc_upl_abort_range(upl, 0, (upl_size_t)upl_size, UPL_ABORT_FREE_ON_EMPTY);+ break;+ }+ /* out of the UPL what this read asked for; then the pages go into the cache */+ copy = (int)(MIN(upl_end, want_end) - pos);+ copy_resid = copy;+ error = cluster_copy_upl_data(uio, upl, (int)(pos - upl_pos), ©_resid);+ ubc_upl_commit_range(upl, 0, (upl_size_t)upl_size, UPL_COMMIT_FREE_ON_EMPTY |+ UPL_COMMIT_INACTIVATE | UPL_COMMIT_CLEAR_DIRTY | UPL_COMMIT_WRITTEN_BY_KERNEL);+ if (error) {+ break;+ }+ if (copy_resid == copy) {+ error = EIO; /* (nothing copied: cannot happen, and must not loop) */+ break;+ }+ }+ return error;+}++/* read(2) the old way: into a buffer of the driver's and out of it, every time (apfs_ubc_read=0) */+static int+apfs_read_direct(struct vnop_read_args *ap){vnode_t vp = ap->a_vp;struct uio *uio = ap->a_uio;@@ -451,15 +610,6 @@ apfs_vnop_read(struct vnop_read_args *ap)struct apfs_lock_proc *lp = NULL;int error = 0;- if (vnode_isdir(vp)) {- return EISDIR;- }- if (!vnode_isreg(vp)) {- return EINVAL;- }- if (uio_offset(uio) < 0) {- return EINVAL;- }ino = APFS_VP(vp)->an_ino;size = APFS_VP(vp)->an_size;t0 = apfs_ticks();@@ -473,8 +623,9 @@ apfs_vnop_read(struct vnop_read_args *ap)apfs_lock(am);{lp = lock_proc(am);- lp->read_calls++;- lp->read_bytes += (uint64_t)MIN((uint64_t)uio_resid(uio), size - (uint64_t)uio_offset(uio));+ os_atomic_inc(&lp->read_calls, relaxed);+ os_atomic_add(&lp->read_bytes,+ (uint64_t)MIN((uint64_t)uio_resid(uio), size - (uint64_t)uio_offset(uio)), relaxed);}/** The lock is held for the reading of each round and let go of for its uiomove;@@ -516,6 +667,49 @@ apfs_vnop_read(struct vnop_read_args *ap)return error;}+static int+apfs_vnop_read(struct vnop_read_args *ap)+{+ vnode_t vp = ap->a_vp;+ struct uio *uio = ap->a_uio;+ struct apfs_mount *am = APFS_VP_MOUNT(vp);+ struct apfs_inode ino;+ struct apfs_lock_proc *lp;+ uint64_t size, t0, before, cached = 0, filled = 0;+ int error = 0;++ if (vnode_isdir(vp)) {+ return EISDIR;+ }+ if (!vnode_isreg(vp)) {+ return EINVAL;+ }+ if (uio_offset(uio) < 0) {+ return EINVAL;+ }+ if (!am->am_ubc_read || !UBCINFOEXISTS(vp)) {+ return apfs_read_direct(ap);+ }+ ino = APFS_VP(vp)->an_ino;+ size = APFS_VP(vp)->an_size;+ t0 = apfs_ticks();+ before = (uint64_t)uio_resid(uio);+ lp = lock_proc(am);+ os_atomic_inc(&lp->read_calls, relaxed);+ if (uio_resid(uio) > 0 && (uint64_t)uio_offset(uio) < size) {+ error = apfs_read_cached(am, vp, uio, &ino, size, &cached, &filled);+ }+ os_atomic_store(&APFS_VP(vp)->an_read_next, (uint64_t)uio_offset(uio), relaxed);+ os_atomic_add(&lp->read_bytes, before - (uint64_t)uio_resid(uio), relaxed);+ os_atomic_add(&lp->read_ticks, apfs_ticks() - t0, relaxed);+ os_atomic_add(&am->am_read_ticks, apfs_ticks() - t0, relaxed);+ os_atomic_inc(&am->am_read_calls, relaxed);+ os_atomic_add(&am->am_read_bytes, before - (uint64_t)uio_resid(uio), relaxed);+ os_atomic_add(&am->am_read_cached, cached, relaxed);+ os_atomic_add(&am->am_read_filled, filled, relaxed);+ return error;+}+/** Page in. Everything goes through apfs_read_file rather than the cluster layer: a* compressed file has no block mapping at all, and a plain one is read out of the extentsdiff --git a/xnu/files/osfmk/arm64/loader_return.c b/xnu/files/osfmk/arm64/loader_return.cindex 1595d1d..e7e2dbb 100644--- a/xnu/files/osfmk/arm64/loader_return.c+++ b/xnu/files/osfmk/arm64/loader_return.c@@ -524,16 +524,19 @@ extern void MiniIOSurfaceUsage(uint32_t *count, uint64_t *bytes);* daemons, and once none is left and it is below the second, whatever is next in line -- the* window server included.*/-static void-memory_report(void)+void redwood_memory_line(char *buf, size_t len);++/* The line itself (also kern.redwood_memory, for a job list to keep: bsd/miscfs/apfs/apfs_vfsops.c) */+void+redwood_memory_line(char *buf, size_t len){#define MB(pages) ((unsigned int)(((uint64_t)(pages) * PAGE_SIZE) >> 20))uint32_t surfaces = 0;uint64_t surface_bytes = 0;MiniIOSurfaceUsage(&surfaces, &surface_bytes);- printf("memory: free %u, files %u, programs %u, wired %u (%u surfaces %u, ramfs %u), compressor %u (holding %u) MB; "- "available %u, kills below %u (the idle) and %u (anybody)\n",+ snprintf(buf, len, "memory: free %u, files %u, programs %u, wired %u (%u surfaces %u, ramfs %u), compressor %u "+ "(holding %u) MB; available %u, kills below %u (the idle) and %u (anybody)\n",MB(vm_page_free_count), MB(vm_page_pageable_external_count), MB(vm_page_pageable_internal_count),MB(vm_page_wire_count), surfaces, (unsigned int)(surface_bytes >> 20),MB(os_atomic_load(&ramfs_pages_in_use, relaxed)),@@ -541,6 +544,15 @@ memory_report(void)MB(memorystatus_available_pages),MB(memorystatus_available_pages_critical), MB(memorystatus_available_pages_critical_base));#undef MB+}++static void+memory_report(void)+{+ char line[256];++ redwood_memory_line(line, sizeof(line));+ printf("%s", line);redwood_adreno_minute(); /* (and how warm the GPU is, if it is in use) */}